INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • 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.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

ASP with API's

Use ASP to get Shipping rates from USPS by schase
Posted: 27 Jul 06

This is similiar to the one for USPS.  So refer back if my notes are somewhat off.  This code is for the testing server.  Like UPS you need to sign up for the WebTools for USPS.  
http://www.usps.com/webtools/welcome.htm

This one just specifies $1.00 to use for handling charge (strChosen)

USPS actually had me just put password in the password field - they say they neither check nor require it - but it didn't work without it.

This one just looks for Parcel Post, Express Mail & Priority Mail.

Good luck :)

CODE

<%
strChosen="1.00"
strXML= "<?xml version='1.0'?><RateV2Request USERID='userID' PASSWORD='password'>"
strXML=strXML & "<Package ID='0'><Service>ALL</Service>"
strXML=strXML & "<ZipOrigination>10022</ZipOrigination>"
strXML=strXML & "<ZipDestination>20008</ZipDestination>"
strXML=strXML & "<Pounds>10</Pounds>"
strXML=strXML & "<Ounces>5</Ounces>"
'strXML=strXML & "<Container>Flat Rate Box</Container>"
strXML=strXML & "<Size>LARGE</Size>"
strXML=strXML & "<Machinable>TRUE</Machinable>"
strXML=strXML & "</Package>"
strXML=strXML & "</RateV2Request>"
strXML=server.URLEncode(strXML)
strXML="API=RateV2&XML=" & strXML
Set strXMLhttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
strXMLhttp.Open "POST","http://testing.shippingapis.com/ShippingAPITest.dll?",false
strXMLhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
strXMLhttp.send strXML
strResponseMessage = strXMLhttp.responseText
intHTTPStatusCode = strXMLhttp.status
strHTTPStatusText = strXMLhttp.statusText
'response.write strResponseMessage & "<BR>"
'response.write intHTTPStatusCode & "<BR>"
'response.write strHTTPStatusText & "<BR>"
'get the response
responsexml = strResponseMessage
Set mydoc=Server.CreateObject("Microsoft.xmlDOM")
mydoc.loadxml(responsexml)
Set NodeList = mydoc.documentElement.selectNodes("Package/Postage")
For strCount = 0 To NodeList.length - 1
Select case Left(NodeList.Item(strCount).selectSingleNode("MailService").Text,6)
case "Parcel"
Session("svUSPS0")="U.S.P.S. Parcel Post"
Session("svUSPSCost0")=(cdbl(NodeList.Item(strCount).selectSingleNode("Rate").Text)+cdbl(strChosen))
Session("svUPSOrder0")=1
strCount2=strCount2+1
CASE "Priori"
Session("svUSPS1")="U.S.P.S. Priority Mail"
Session("svUSPSCost1")=(cdbl(NodeList.Item(strCount).selectSingleNode("Rate").Text)+cdbl(strChosen))
Session("svUPSOrder1")=1
strCount2=strCount2+1
CASE "Expres"
Session("svUSPS2")="U.S.P.S. Express Mail"
Session("svUSPSCost2")=(cdbl(NodeList.Item(strCount).selectSingleNode("Rate").Text)+cdbl(strChosen))
Session("svUPSOrder2")=1
strCount2=strCount2+1
END SELECT
NEXT
session("svCount")=clng(strCount2)
response.write strCount2 & "<BR>"
'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"))="&nbsp;" 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("svUSPS"&strCount) THEN
response.write("<option value=""" & Session("svUSPS"&strCount) & """ selected>")
ELSE
response.write("<option value=""" & Session("svUSPS"&strCount) & """>")
END IF
response.write Session("svUSPS"&strCount) & " - " & formatcurrency((Session("svUSPSCost"&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

My Archive

Resources

Close Box

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:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close