Server Time:
Monday May 12 2008 09:57 AM  
Your Time:
  
HostMySite.Com is sponsoring this tutorial, please visit their site today!
This tutorial is sponsored by HostMySite.Com - ColdFusion Hosting

integrate UPS tools with coldfusion
by: chhchung
Email this tutorial to a friend Display Printer Friendly Format
[Download in PDF Format] [Download in FlashPaper Format]

<!--- Before you start reading this tutorial, I suggest you read the ups documentation
       first and apply the xml developer access key--->
<!--- Please visite www.ec.ups.com to have your access key --->
<!--- You can add the special servcie by change the xml code below, for example saturday pick up service--->
<!--- Build UPS XML Packet ---> 


<cfsavecontent variable="XMLPacket"><cfoutput> 
<?xml version="1.0"?>
    <AccessRequest xml:lang=
"en-US">
    <AccessLicenseNumber>
#accessLicenseNumber#</AccessLicenseNumber>
    <UserId>
#userid#</UserId>
    <Password>
#password#</Password>
</AccessRequest>
<?xml version=
"1.0"?>
    <RatingServiceSelectionRequest xml:lang=
"en-US">
        <Request>
            <TransactionReference>
                <CustomerContext>
Bare Bones Rate Request</CustomerContext>
                <XpciVersion>
1.0001</XpciVersion>
            </TransactionReference>
            <RequestAction>
Rate</RequestAction>
            <RequestOption>
Shop</RequestOption>
        </Request>
        <PickupType>
            <Code>
01</Code>
        </PickupType>
        <Shipment>
            <Shipper>
                <Address>
                    <PostalCode>
11214</PostalCode>
                    <CountryCode>
US</CountryCode>
                </Address>
            </Shipper>
            <ShipTo>
                <Address>
                    <PostalCode>
07083</PostalCode>
                    <CountryCode>
US</CountryCode>
                </Address>
            </ShipTo>
            <ShipFrom>
                <Address>
                    <PostalCode>
11213</PostalCode>
                    <CountryCode>
US</CountryCode>
                </Address>
            </ShipFrom>
            <Service>
                <Code>
01</Code>
            </Service>
            <Package>
                <PackagingType>
                    <Code>
02</Code>
                </PackagingType>
                <Dimensions>
                    <UnitOfMeasurement>
                        <Code>
IN</Code>
                    </UnitOfMeasurement>
                    <Length>
20</Length>
                    <Width>
20</Width>
                    <Height>
20</Height>
                </Dimensions>
                <PackageWeight>
                    <UnitOfMeasurement>
                        <Code>
LBS</Code>
                    </UnitOfMeasurement>
                    <Weight>
23</Weight>
                </PackageWeight>
            </Package>
        </Shipment>
    </RatingServiceSelectionRequest>
</cfoutput></cfsavecontent> 



<cfhttp url="https://www.ups.com/ups.app/xml/Rate" port="443" method ="POST" throwonerror="yes"

    <cfhttpparam name=
"name" type="XML" value="#XMLPacket#"

</cfhttp> 

<cfset xmlfile = XmlParse(CFHTTP.FileContent)>
<cfif xmlfile.RatingServiceSelectionResponse.Response.ResponseStatusCode.xmlText eq 1>


    <!--- the code below you may think familiar, yes. I grab it from tutorial195.easycfm.com --->
    <!--- If you don't understand the code below, i suggest you go to original author's tutorial --->

    <cfscript>

        xmlsize = arrayLen(xmlfile.RatingServiceSelectionResponse.xmlchildren) - 1;
        xmlqry = QueryNew("code,money");
        QueryAddRow(xmlqry,xmlsize);

        for(a=1;a lte xmlsize; a=a+1){
            QuerySetCell(xmlqry,"code",xmlfile.RatingServiceSelectionResponse.RatedShipment[a].Service.Code.xmlText,a);
        QuerySetCell(xmlqry,"money",xmlfile.RatingServiceSelectionResponse.RatedShipment[a].TotalCharges.MonetaryValue.xmlText,a);
        }
    </cfscript>

    <cfquery name="ups" dbtype="query">
        select *
        from xmlqry
    </cfquery>

    <!--- the code below show the method of shipping and the price --->
    <cfoutput query="ups">
        UPS(<cfswitch expression="#code#">

        <cfcase value="01">Next Day Air</cfcase>
        <cfcase value=
"02">2nd Day Air</cfcase>
        <cfcase value=
"03">Ground</cfcase>
        <cfcase value=
"07">Worldwide Express</cfcase>
        <cfcase value=
"08">Worldwide Expedited</cfcase>
        <cfcase value=
"11">Standard</cfcase> 
        <cfcase value=
"12">3 Day Select</cfcase>
        <cfcase value=
"13">Next Day Air Saver</cfcase>
        <cfcase value=
"14">Next Day Air Early A.M.</cfcase>
        <cfcase value=
"54">Worldwide Express Plus</cfcase>
        <cfcase value=
"59">UPS 2nd Day Air A.M.</cfcase>
        <cfcase value=
"64">n/a</cfcase>
        <cfcase value=
"65">UPS Express Saver</cfcase>

        </cfswitch>
) #money#
    </cfoutput>
</cfif>


<!--- If you like to see the live demo of the code , please visit my site --->
<!--- http://www.anawholesale.com/product.cfm --->


Date added: Wed. December 17, 2003
Posted by: chhchung | Views: 9785 | Tested Platforms: CFMX | Difficulty: Intermediate
Categories Listed: Ecommerce

HostMySite.Com is sponsoring this tutorial, please visit their site today!
This tutorial is sponsored by HostMySite.Com - ColdFusion Hosting

Please rate this tutorial:
5 Stars 4 Stars 3 Stars 2 Stars 1 Stars
Comments on this tutorial
Read previous comments on this particular tutorial
Awesome!
Thank you so much for saving me a couple hours of going through the 150 page developer document for such a simple application.

Why does UPS make it so hard?

Its works great, thanks again!

Ryan Jones
ryan@other-world.com

Posted by: Ryan Jones
Posted on: 04/14/2004 09:01 PM
Ok I'm at witts end
I myself am trying to intergrate ups into a web cart that I am creating for my own site. I was easily able to create and manage the above turtorial (which by the way I thank you for),but now I am trying to use the tracking part of the UPS tools and It looks like it wants to pull the data, but is coming up with an error on XML from UPS. I am not totally sure on this and would like some help. Here is my error message:

Expected "</br>" to terminate element starting on line 8.
Expected "
" to terminate element starting on line 8.

The error occurred in C:\CFusionMX\wwwroot\www.clearcg.com\testing XML\Untitled-5.cfm: line 24

22 : <cfhttpparam type="url" name="UPS_Construct_Tracking" value="#UPSXMLPacket#">
23 : </cfhttp>
24 : ***<cfset upsxmlfile = XmlParse(CFHTTP.FileContent)>***
25 : <cfscript>
26 : ups=arrayLen(upsxmlfile.TimeInTransitResponse.xmlchildren)-1;

Line 24 <cfset upsfile=XMLParse(cfhttp.filecontent)> is where the error says occured, but I don't see how I go that kind of error if there is no <br> tag there unless it is on the UPS server side. I would just like to know if the error is mine or their's. I am using the "https://wwwcie.ups.com/ups.app/xml/Track" url which is the testing server for them.



Posted by: Craig
Posted on: 03/10/2005 06:20 PM
Great Help
This made my day a lot shorter, thanks for the hard work.
Posted by: Connor
Posted on: 06/29/2005 03:00 PM
Post a new comment on this tutorial
post a new comment on this particular tutorial
Your Name:
Your Email:
Comment Title:
Comments:
Key Phrase:
 
Skyscrapper Banner Advertisement
CF 8 Hosting for less then $40 a year!

You are 1 of 556 active sessions! | Privacy | Company
Copyright © 2002 EasyCFM.Com, LLC. (Easy ColdFusion Tutorials) All Rights Reserved
All other trademarks and copyrights are the property of their respective holders.
ColdFusion Hosting ColdFusion Hosting
ADD TO:
Blink
Del.icio.us
Digg
Furl
Google
Simpy
Spurl
Y! MyWeb