Miscellaneous Code
  Home arrow Miscellaneous Code arrow UPS Cost Calculation
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MISCELLANEOUS CODE

UPS Cost Calculation
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 2
    2004-05-26

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    With this class you can find out how much you have to pay for delivering product using UPS.

    By : hermawan

    <?php
    /**
    * UPS Shipping Calculation Class
    * @author Hermawan Haryanto
    * @date May 26, 2004
    * @description
    * This class is returning the cost of shipping using UPS
    * Tested works for USA
    * Please notify me if it's work for other contry

    UPS PRODUCT CODE (this should be in a drop down menu)
    Next Day Air Early AM 1DM
    Next Day Air 1DA
    Next Day Air Saver 1DP
    2nd Day Air AM 2DM
    2nd Day Air 2DA
    3 Day Select 3DS
    Ground GND
    Canada Standard STD
    Worldwide Express XPR
    Worldwide Express Plus XDM
    Worldwide Expedited XPD

    UPS RATE CHART
    Regular+Daily+Pickup
    On+Call+Air
    One+Time+Pickup
    Letter+Center
    Customer+Counter

    Container Chart
    Customers Packaging 00

    UPS Letter Envelope 01
    or
    UPS Tube

    UPS Express Box 21
    UPS Worldwide 25kg Box 22
    UPS Worldwide 10 kg Box 23

    ResCom UPS Table
    Residential 1
    Commercial 2
    */
    class ups
    {
    var $_action;
    var $_delivery_code;
    var $_src_zip;
    var $_dst_zip;
    var $_weight;
    var $_src_country;
    var $_dst_country;
    var $_rate_chart;
    var $_rate_charts;
    var $_container;
    var $_containers;
    var $_rescom;
    var $_rescoms;
    var $_errors;
    function ups()
    {
    $this->_errors = array();
    $this->_action = 3;
    $this->_delivery_code = 'GND';
    $this->_src_country = 'US';
    $this->_dst_country = 'US';
    $this->_rate_chart = 1;
    $this->_container = '0';
    $this->_rescom = 1;
    $this->_rate_charts = array('Regular+Daily+Pickup',
    'On+Call+Air',
    'One+Time+Pickup',
    'Letter+Center',
    'Customer+Counter');
    $this->_containers = array ('00', '01', '21', '22', '23', '1', '2');
    $this->_rescoms = array ('1', '2');

    }
    function set_rescom ($int)
    {
    $this->_rescom = $int;
    }
    function set_container ($int)
    {
    $this->_container = $int;
    }
    function set_rate_chart($int)
    {
    $this->_rate_chart = 1;
    }
    function set_action($int)
    {
    $this->_action = $int;
    }
    function set_delivery_code ($code)
    {
    $this->_delivery_code = $code;
    }
    function set_src_zip ($zip)
    {
    $this->_src_zip = $zip;
    }
    function set_dst_zip ($zip)
    {
    $this->_dst_zip = $zip;
    }
    function set_src_country ($code)
    {
    $this->_src_country = $code;
    }
    function set_dst_country ($code)
    {
    $this->_dst_country = $code;
    }
    function set_weight ($int)
    {
    $this->_weight = $int;
    }
    function get_cost ()
    {
    if ($this->_action == '')
    array_push ($this->_errors, 'UPS Action is not defined');
    if ($this->_delivery_code == '')
    array_push ($this->_errors, 'UPS Product Code is not defined');
    if ($this->_src_zip == '')
    array_push ($this->_errors, 'Source Zip Code is unavailable');
    if ($this->_src_country == '')
    array_push ($this->_errors, 'Source Country Code is unavailable');
    if ($this->_dst_zip == '')
    array_push ($this->_errors, 'Destination Zip Code is unavailable');
    if ($this->_dst_country == '')
    array_push ($this->_errors, 'Destination Country Code is unavailable');
    if ($this->_weight == '')
    array_push ($this->_errors, 'Packet weight is not defined');
    if ($this->_rate_chart == '')
    array_push ($this->_errors, 'Rate Chart is not defined');
    if ($this->_container == '')
    array_push ($this->_errors, 'Client Shipping Package Type is not defined');
    if ($this->_rescom == '')
    array_push ($this->_errors, 'Residential or Commercial? define it first!');
    if (count ($this->_errors) <= 0)
    {
    $url = 'www.ups.com';
    $port = '80';
    $file = '/using/services/rave/qcostcgi.cgi';
    $qs = '?';
    $qs .= 'accept_UPS_license_agreement=yes';
    $qs .= '&';
    $qs .= '10_action='.$this->_action;
    $qs .= '&';
    $qs .= '13_product='.$this->_delivery_code;
    $qs .= '&';
    $qs .= '14_origCountry='. $this->_src_country;
    $qs .= '&';
    $qs .= '15_origPostal='. $this->_src_zip;
    $qs .= '&';
    $qs .= '19_destPostal='. $this->_dst_zip;
    $qs .= '&';
    $qs .= '22_destCountry='. $this->_dst_country;
    $qs .= '&';
    $qs .= '23_weight='. $this->_weight;
    $qs .= '&';
    $qs .= '47_rateChart='.$this->_rate_charts[$this->_rate_chart];
    $qs .= '&';
    $qs .= '48_container='.$this->_rate_containers[$this->_rate_container];
    $qs .= '&';
    $qs .= '49_residential='.$this->_rescoms[$this->_rescom];
    $rqs = $file.$qs;
    $fp = @fsockopen ($url, 80, &$errno, &$errstr, 30);
    if (!$fp) array_push ($this->_errors, 'Could not open socket');
    else
    {
    fputs($fp,"GET $rqs HTTP/1.0\n\n");
    while(!feof($fp))
    {
    $buffer = fgets ($fp, 1024);
    if (strpos ($buffer, '%'))
    {
    $buffers = explode ('%', $buffer, -1);
    $errcode = substr ($buffers[0], -1);
    $goodcodes = array ('3', '4', '5', '6');
    if (in_array ($errcode, $goodcodes))
    {
    $cost = trim ($buffers[8]);
    return $cost;
    }
    else array_push ($this->_errors, 'Bad Result');
    }
    }
    fclose($fp);
    }
    }
    }
    }
    $ups = new ups;
    $ups->set_src_zip('08053');
    $ups->set_dst_zip('08055');
    $ups->set_weight (5);
    $ups_cost = $ups->get_cost();
    if (!$ups_cost) print_r ($ups->_errors);
    else print $ups_cost;
    ?>
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Miscellaneous Code Articles
    More By Codewalkers

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! IBM – Taking Web 2.0 to Work

    David Barnes, Lead Evangelist for IBM Emerging Internet Technologies will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve.
    FREE! Go There Now!


    NEW! Cook up Web sites fast with CakePHP, Part 4: Use CakePHP&apos;s Session and Request Handler components

    CakePHP is a stable production-ready, rapid-development aid for building Web sites in PHP. This "Cook up Web sites fast with CakePHP" series shows you how to build an online product catalog using CakePHP.
    FREE! Go There Now!


    NEW! Discovering the value of WebSphere Process Server

    WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies.
    FREE! Go There Now!


    NEW! Evaluate Rational Host Access Transformation Services (HATS) Toolkit V7.1

    Visit IBM developerWorks to download a free trial of the Rational Host Access Transformation Services (HATS) Toolkit. The HATS toolkit provides a set of plug-ins for the IBM Rational Software Delivery Platform to help you easily extend your legacy applications. HATS makes your 3270 and 5250 applications available as HTML through the most popular Web browsers, while converting your host screens to a Web look and feel and it also enables you to develop new Web, portal, and rich-client applications.
    FREE! Go There Now!


    NEW! Evaluate WebSphere Extended Deployment Compute Grid V6.1

    Visit IBM developerWorks to download a free trial version of WebSphere Extended Deployment Compute Grid, which lets you schedule, execute, and monitor batch jobs. Because online transaction processing and batch jobs execute simultaneously on the same server resources, you can avoid costly duplication of resources. Compute Grid supports job types of Java transactional batch, compute-intensive and a new type called "native execution", which enables non-Java workloads to run on distributed end points.
    FREE! Go There Now!


    NEW! Rational 'Talks to You' Teleconference Series

    This Fall, IBM Rational talks to you directly through a special teleconference series giving you access to the best minds in IBM Rational - product experts and market thought leaders who will answer your questions during these pre-scheduled telephone conference calls. Register today!
    FREE! Go There Now!


    NEW! Try the IBM SOA Sandbox for People

    Visit IBM developerWorks to try the IBM SOA Sandbox for people. The SOA Sandbox for people provides a trial environment with the necessary tooling and components required to enable consistent human and process interaction and collaboration, showing how you can improve user experience and business productivity.
    FREE! Go There Now!


    NEW! Webcast: Accelerating Software Innovation with System z

    Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, where he will overview Rational’s new offerings and programs to help customers accelerate software innovation on System z. He will discuss how these solutions help organizations extend their core business processes toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time.
    FREE! Go There Now!


    NEW! Webcast: IBM Rational Build Forge - Beyond the Build

    The discipline of assembling and delivering software is maturing beyond standard developer-centric compile/test software builds. The end-to-end software development lifecycle is emerging as the new focus moves “Beyond the Build.” Join this on demand webcast to learn about methods for streamlining software delivery and key capabilities of the IBM Rational Build Forge framework for automating build and release management in environments of any size.
    FREE! Go There Now!


    NEW! Webcast: Introducing the new Information Server and Solutions community: LeverageInformation

    User communities play an important role in communication and collaboration around products, solutions and other areas of special interest to members. Successful communities are able to provide the right mix of content and services to deliver a value proposition that resonates with each audience. Join Tom Inman, VP of Marketing for Information and Platform Solutions as he introduces the new LeverageINFORMATION community. During this webcast, learn about the value provided by the community and how customers and partners derive value from the community in addressing their own technical and business challenges.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    MISCELLANEOUS CODE ARTICLES

    - A Web App Based on a Model for the CodeIgnit...
    - Completing a Model for the CodeIgniter PHP F...
    - Validating Input Data with the CodeIgniter P...
    - Deleting Database Records with the CodeIgnit...
    - Inserting Database Records with a CodeIgnite...
    - Fetching Database Rows with a Model for the ...
    - Model Data and Validation Rules for a Generi...
    - Building a Generic Model for the CodeIgniter...
    - upload image to database sql
    - Random Password Generator
    - BCroot, get the root of a number with BC fun...
    - Find pi in a high precision
    - [PHP5] FORMCHECKER : data validation
    - SPL and ITERATOR : examples
    - Xml with Rss Feeds





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek