INTELLIGENT WORK FORUMS FOR COMPUTER PROFESSIONALS
Come Join Us!
Are you a Computer / IT professional? Join Tek-Tips now!
- Talk With Other Members
- Be Notified Of Responses
To Your Posts
- Keyword Search
- One-Click Access To Your
Favorite Forums
- Automated Signatures
On Your Posts
- Best Of All, It's Free!
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.
Partner With Us!
"Best Of Breed" Forums Add Stickiness To Your Site

(Download This Button Today!)
Feedback
"...I just wanted to say how much I have enjoyed these forums. I am a new user and have a lot of elementary questions. I get quick answers with a friendly attitude..."
Geography
Where in the world do Tek-Tips members come from?
|
Microsoft: ASP (Active Server Pages) FAQ
|
ASP with API's
|
Use ASP to Get shipping rates from UPS.
Posted: 27 Jul 06
|
This will get the rates from UPS and put them into a dropdown box. You do need to sign up with UPS and get an access key and probably a developers key.
http://www.ups.com/content/us/en/bussol/offering/technology/automated_shipping/online_tools.html
Of course change Access number, User ID & Password with your own. Please note I put any dims into a separate page. In this I have also included a method to pull a specific dollar amount for handling charges (strChosen) substitute the sql below for it and jut put strChosen=1, 2, whatever value you want.
Define both elements below.
strCompanyPostCode = whatever zip code you are sending from orderWeight = the total weight of the package.
Good luck :)
CODE<% 'create XML to send to UPS to gather rates strXML= "<?xml version='1.0'?><AccessRequest xml:lang='en-US'><AccessLicenseNumber>xxxxxxxxxxxxxxxx</AccessLicenseNumber><UserId>xxxxxxxxxx</UserId><Password>xxxxxxxxxxxx</Password></AccessRequest>" strXML=strXML & "<?xml version='1.0'?><RatingServiceSelectionRequest xml:lang='en-US'><Request><TransactionReference><CustomerContext>Rating and Service</CustomerContext><XpciVersion>1.0001</XpciVersion></TransactionReference><RequestAction>Rate</RequestAction><RequestOption>shop</RequestOption></Request>" strXML=strXML & "<PickupType><Code>01</Code></PickupType><Shipment><Shipper><Address><PostalCode>" & strCompanyPostCode & "</PostalCode></Address></Shipper>" strXML=strXML & "<ShipTo><Address><PostalCode>" & (request("txtShipPostCode")) & "</PostalCode></Address></ShipTo>" strXML=strXML & "<Service><Code>11</Code></Service>" strXML=strXML & "<Package><PackagingType><Code>02</Code><Description>Package</Description></PackagingType><Description>Rate Shopping</Description>" strXML=strXML & "<PackageWeight><Weight>" & orderWeight & "</Weight></PackageWeight></Package>" strXML=strXML & "<ShipmentServiceOptions/></Shipment></RatingServiceSelectionRequest>" Set strXMLhttp = Server.CreateObject("MSXML2.ServerXMLHTTP") 'send it strXMLhttp.Open "POST","https://www.ups.com/ups.app/xml/Rate?",false strXMLhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" strXMLhttp.send strXML 'pull any shipping surcharges from the database that we set up. BDSQL="Select fldShipping from tblShipping where fldVisible=1;" set BDTemp=BDConn.execute(BDSQL) IF BDTemp.EOF THEN strChosen=0 else strChosen=BDTemp("fldShipping") END IF 'the response from UPS strXMLResponse = strXMLhttp.responseText Set mydoc=Server.CreateObject("Microsoft.xmlDOM") mydoc.loadxml(strXMLResponse) 'Create A Nodelist of All The RatedShipments Set NodeList = mydoc.documentElement.selectNodes("RatedShipment") For strCount = 0 To NodeList.length - 1 'Service/Code 'put into session value any codes we choose to use - being Next day, 2nd day, 3 day and ground. Select case NodeList.Item(strCount).selectSingleNode("Service/Code").Text case "01" session("svUPS3")="UPS Next Day Air" session("svUPSCost3")=(cdbl(NodeList.Item(strCount).selectSingleNode("TotalCharges/MonetaryValue").Text)+cdbl(strChosen)) session("svUPSOrder3")=3 strCount2=strCount2+1 case "02" session("svUPS2")="UPS 2nd Day Air" session("svUPSCost2")=(cdbl(NodeList.Item(strCount).selectSingleNode("TotalCharges/MonetaryValue").Text)+cdbl(strChosen)) session("svUPSOrder2")=2 strCount2=strCount2+1 case "12" session("svUPS1")="UPS 3 Day Select" session("svUPSCost1")=(cdbl(NodeList.Item(strCount).selectSingleNode("TotalCharges/MonetaryValue").Text)+cdbl(strChosen)) session("svUPSOrder1")=1 strCount2=strCount2+1 case "03" session("svUPS0")="UPS Ground" session("svUPSCost0")=(cdbl(NodeList.Item(strCount).selectSingleNode("TotalCharges/MonetaryValue").Text )+cdbl(strChosen)) session("svUPSOrder0")=0 strCount2=strCount2+1 END SELECT NEXT session("svCount")=clng(strCount2) 'Create a select table from the response xml response.Write("<select name=""txtShipping"" class=""searchfield"">") & vbcrlf IF (request("txtShipping"))="0" or (request("txtShipping"))="" or (request("txtshipping"))=" " or isNULL((request("txtshipping"))) THEN response.write "<Option value=""0"" selected><-- Select Shipping --></option>" & vbcrlf ELSE response.write "<Option value=""0""><-- Select Shipping --></option>" & vbcrlf END IF 'TotalCharges/MonetaryValue For strCount=0 to (clng(session("svCount"))-1) IF (request("txtShipping"))= Session("svUPS"&strCount) THEN response.write("<option value=""" & Session("svUPS"&strCount) & """ selected>") ELSE response.write("<option value=""" & Session("svUPS"&strCount) & """>") END IF response.write Session("svUPS"&strCount) & " - " & formatcurrency((Session("svUPSCost"&strCount)),2) response.write("</option>") & vbcrlf Next response.Write("</select>") & vbcrlf |
Back to Microsoft: ASP (Active Server Pages) FAQ Index
Back to Microsoft: ASP (Active Server Pages) Forum |
|
 |
|
Join Tek-Tips® Today!
Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.
Here's Why Members Love Tek-Tips Forums:
Talk To Other Members
- Notification Of Responses To Questions
- Favorite Forums One Click Access
- Keyword Search Of All Posts, And More...
Register now while it's still free!
Already a member? Close this window and log in.
Join Us Close