By: Ayhan
Untitled Document <cfset form.city="Broadview Heights">
<cfset form.state=
"OH">
<cfset form.zip=
"44147">
<cfset shipdate=
Now()>

<cfsavecontent variable="TNT">
   <cfoutput>
     
 <?xml version="1.0"?>
         <AccessRequest xml:lang=
"en-US">
            <AccessLicenseNumber>
YOUR LICENSE NUMBER</AccessLicenseNumber>
               <UserId>
USERID</UserId>
               <Password>
PASSWORD</Password>
            </AccessRequest>
            <?xml version=
"1.0"?>
               <TimeInTransitRequest xml:lang=
"en-US">
                  <Request>
                     <TransactionReference>
                        <XpciVersion>
1.0002</XpciVersion>
                     </TransactionReference>
                     <RequestAction>
TimeInTransit</RequestAction>
                  </Request>
                  <TransitFrom>
                     <AddressArtifactFormat>
                        <CountryCode>
US</CountryCode>
                        <PostcodePrimaryLow>
11232</PostcodePrimaryLow>
                     </AddressArtifactFormat>
                  </TransitFrom>
                  <TransitTo>
                     <AddressArtifactFormat>
                        <CountryCode>
US</CountryCode>
                        <PoliticalDivision2>
#form.city#</PoliticalDivision2>
                        <PoliticalDivision1>
#form.state#</PoliticalDivision1>
                        <PostcodePrimaryLow>
#form.zip#</PostcodePrimaryLow>
                        <ResidentialAddressIndicator>
1</ResidentialAddressIndicator>
                     </AddressArtifactFormat>
                  </TransitTo>
                  <PickupDate>
#DateFormat(shipdate,'YYYYMMDD')#</PickupDate>
               </TimeInTransitRequest>
</cfoutput>
</cfsavecontent>
<cfhttp url=
"https://www.ups.com/ups.app/xml/TimeInTransit" port="443" method="POST" throwonerror="yes">
     <cfhttpparam name=
"requestTNT" type="XML" value="#TNT#">
</cfhttp>

<cfset TNTData = XmlParse(CFHTTP.FileContent)>
<cfloop from=
"1" to="#ArrayLen(TNTData.TimeInTransitResponse.TransitResponse.ServiceSummary)#" index="i">
     <cfset services[
i]=structnew()>
     <cfset services[
i].code=TNTData.TimeInTransitResponse.TransitResponse.ServiceSummary[i].Service.Code.xmlText>
     <cfset services[
i].type=TNTData.TimeInTransitResponse.TransitResponse.ServiceSummary[i].Service.Description.xmlText>
     <cfset services[
i].tt=TNTData.TimeInTransitResponse.TransitResponse.ServiceSummary[i].EstimatedArrival.BusinessTransitDays.xmlText>
     <cfset services[
i].arrivaldate=TNTData.TimeInTransitResponse.TransitResponse.ServiceSummary[i].EstimatedArrival.Date.xmlText>
     <cfset services[
i].arrivaltime=TNTData.TimeInTransitResponse.TransitResponse.ServiceSummary[i].EstimatedArrival.Time.xmlText>
</cfloop>

<cfsavecontent variable="GetRate">
   <cfoutput>
      <?xml version="1.0"?>
         <AccessRequest xml:lang=
"en-US">
            <AccessLicenseNumber>
YOUR LICENSE NUMBER</AccessLicenseNumber>
            <UserId>
USERID</UserId>
            <Password>
PASSWORD</Password>
         </AccessRequest>
         <?xml version=
"1.0"?>
         <RatingServiceSelectionRequest xml:lang=
"en-US">
            <Request>
               <RequestAction>
Rate</RequestAction>
               <RequestOption>
Shop</RequestOption>
            </Request>
            <PickupType>
               <Code>
1</Code>
            </PickupType>
            <Shipment>
               <Shipper>
                  <Address>
                     <PostalCode>
11232</PostalCode>
                     <CountryCode>
US</CountryCode>
                  </Address>
               </Shipper>
               <ShipTo>
                  <Address>
                     <PostalCode>
#form.zip#</PostalCode>
                     <CountryCode>
US</CountryCode>
                     <ResidentialAddressIndicator>
1</ResidentialAddressIndicator>
                  </Address>
               </ShipTo>
               <Service>
                  <Code>
01</Code>
               </Service>
               <Package>
                  <PackagingType>
                     <Code>
02</Code>
                  </PackagingType>
                  <PackageWeight>
                     <UnitOfMeasurement>
                        <Code>
LBS</Code>
                     </UnitOfMeasurement>
                     <Weight>
10</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=
"requestRate" type="XML" value="#GetRate#">
</cfhttp>



<cfset rateData = XmlParse(CFHTTP.FileContent)>
<cfloop from=
"1" to="#ArrayLen(rateData.RatingServiceSelectionResponse.RatedShipment)#" index="i">
   <cfset rates[
i]=structnew()>
   <cfset rates[
i].price=rateData.RatingServiceSelectionResponse.RatedShipment[i].TotalCharges.MonetaryValue.xmlText>
   <cfswitch expression="#rateData.RatingServiceSelectionResponse.RatedShipment[
i].Service.Code.xmlText#">
      <cfcase value=
"01">
         <cfset NextDayAir=rates[
i].price>
      </cfcase>
      <cfcase value=
"02">
         <cfset SecondDayAir=rates[
i].price>
      </cfcase>
      <cfcase value=
"03">
         <cfset Ground=rates[
i].price>
      </cfcase>
      <cfcase value=
"12">
         <cfset ThreeDaySelect=rates[
i].price>
      </cfcase>
      <cfcase value=
"13">
         <cfset NextDayAirSaver=rates[
i].price>
      </cfcase>
      <cfcase value=
"14">
         <cfset NextDayAirEarly=rates[
i].price>
      </cfcase>
      <cfcase value=
"59">
         <cfset SecondDayAirAM=rates[
i].price>
      </cfcase>
   </cfswitch>
</cfloop>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>
Untitled Document</title>
<meta http-equiv=
"Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
Ship Date:<cfoutput>
#DateFormat(shipdate,'mmm dd, yyyy')#
</cfoutput><br>

shipping options <br>

<cfloop from="1" to="#ArrayLen(services)#" index="i">
   <cfset newdate=DateAdd(
'w',1,services[i].arrivaldate)>
   <cfoutput>
   <cfswitch expression=
"#services[i].code#">
      <cfcase value=
"GND">
         
#DollarFormat(Ground)#
      </cfcase>
      <cfcase value=
"2DA">
         
#DollarFormat(SecondDayAir)#
      </cfcase>
      <cfcase value=
"1DP">
         
#DollarFormat(NextDayAirSaver)#
      </cfcase>
      <cfcase value=
"1DA">
         
#DollarFormat(NextDayAir)#
      </cfcase>
      <cfcase value=
"1DM">
         
#DollarFormat(NextDayAirEarly)#
      </cfcase>
      <cfcase value=
"2DM">
         
#DollarFormat(SecondDayAirAM)#
      </cfcase>
      <cfcase value=
"3DS">
         
#DollarFormat(ThreeDaySelect)#
      </cfcase>
</cfswitch>
#services[i].type#-#services[i].tt# Business Days--Est Arrival date: #DateFormat(services[i].arrivaldate,'MM/DD/YY')# <cfif TimeFormat(services[i].arrivaltime,'tt') is 'AM' >#TimeFormat(services[i].arrivaltime,'hh:mm:tt')#</cfif> <br>
</cfoutput>
</cfloop>

<br>
<br>
<br>
</body>
</html>

About This Tutorial
Author: Ayhan
Skill Level: Advanced 
 
 
 
Platforms Tested: CFMX,CFMX7
Total Views: 90,723
Submission Date: May 12, 2005
Last Update Date: June 05, 2009
All Tutorials By This Autor: 4
Discuss This Tutorial
  • how do you handle timeouts? what if the service is down or your server is lagging?

  • Works for me. Thanks much! If you're allowing the end-user to get a time/cost quote by choosing a UPS service option from a form select tag remember that 3Day Select isn't offered to Hawaii, Alaska, etc. Code with this in mind.

  • Nice script. You just need to have a developer account with UPS and supply your license number in the code.

  • All info in this site are jumbled. Please check this site.

  • Is this supposed to be one page? Cause I used this code on one page and got this error message: Type Application Detail Invalid value specified for the TYPE attribute. Tag Context CFHTTP: Line=40; Column=1 | +-- CFHTTPPARAM: Line=41; Column=6 Source 38: 39: 40: 41: 42: I have been trying to get the UPS Tools to work for the last two days, so any help would be great!

Advertisement

Sponsored By...
Dripping Springs, Texas - Deep Tissue Massages and Swedish Massages!