<%@ Language=VBScript %> <% 'Con-way XML Sample Code for ASP - Bill of Lading interface '----------------- 'TODO: replace the USERNAME and PASSWORD String values below 'with your Con-way username and password 'and include one or more valid tracking numbers below '----------------- 'Send questions to Con-way XML Support at xmlsupport@Con-way.com Option Explicit ' Declare Variables Dim title ' Dim requestType 'The XML Request type Dim conwayXmlUrl 'The secure POST URL for the XML Request Dim xmlRequest 'a string to hold XML Request document Dim xmlResponse 'an XML DOM object to hold the XML Response document Dim myElement1 'first element to retrieve from XML Response Dim myElement2 'second element to retrieve from XML Response Dim myElementList1 'NodeList for my first element Dim myElementList2 'NodeList for my second element Dim today 'String to hold today's date Dim mo 'String to hold month Dim dy 'String to hold day Dim yr 'String to hold year Dim httpConn 'an object for the HTTP connection to www.Con-way.com Dim username 'for authentication to Con-way secure site Dim password 'for authentication to Con-way secure site Dim myInputArgs() 'array to hold your input arguments title = "Bill of Lading" requestType = "BOLrequest" conwayXmlUrl = "https://www.Con-way.com/XMLj/X-BOL" myElement1 = "Status" myElement2 = "Consignee" ' replace the "USERNAME" & "PASSWORD" String values with your Con-way username and password username = "USERNAME" password = "PASSWORD" today = Date() ' year must be 2 digit to conform to our XML Schema yr = Year(today) if len(yr) = 4 then yr = Mid(yr,3) mo = Month(today) dy = Day(today) today = mo & "/" & dy & "/" & yr end if '*Build Rate Request ' In actual use, you would probably populate the Rating Request ' parameters (Weights, Classes, Zip Codes, etc.) from data submitted ' via an on-line order form or database. ' For this sample we will just hard code some dummy data. xmlRequest="<BOLrequest testmode=""Y"">" &_ "<RequesterUserId shipcode=""S"">" & username & "</RequesterUserId>" &_ "<ChargeCode>P</ChargeCode>" &_ "<PRONmbr></PRONmbr>" &_ "<CustRefNmbrs>" &_ "<PurchaseOrderNmbr>3338889</PurchaseOrderNmbr>" &_ "<PurchaseOrderNmbr>3338890</PurchaseOrderNmbr>" &_ "<OtherRefNmbr refcode=""SKU"" refdesc=""SKU Number"">3213A</OtherRefNmbr>" &_ "<OtherRefNmbr refcode=""UPC"" refdesc=""UPC number"">789283</OtherRefNmbr>" &_ "</CustRefNmbrs>" &_ "<Shipper>" &_ "<ShipperName>Alan Shipley</ShipperName>" &_ "<ShipperAddr>1234 NE Main</ShipperAddr>" &_ "<ShipperCity>Portland</ShipperCity>" &_ "<ShipperState>OR</ShipperState>" &_ "<ShipperZip country=""US"">97202</ShipperZip>" &_ "<ShipperPhone extension=""6055"">800-555-1212</ShipperPhone>" &_ "<ShipperEmail>youremail@yourcompany.com</ShipperEmail>" &_ "</Shipper>" &_ "<COD>" &_ "<CODremitTo>" &_ "<CODremitToName>Albert Cod</CODremitToName>" &_ "<CODremitToAddr>1234 NE Main</CODremitToAddr>" &_ "<CODremitToCity>Portland</CODremitToCity>" &_ "<CODremitToState>OR</CODremitToState>" &_ "<CODremitToZip country=""US"">97202</CODremitToZip>" &_ "</CODremitTo>" &_ "<CODamount pmttype=""CustomerCheck"" chargecode=""P"">4444.44</CODamount>" &_ "</COD>" &_ "<Consignee>" &_ "<ConsigneeCustNmbr>883885</ConsigneeCustNmbr>" &_ "<ConsigneePhone extension=""6666"">503.450.6800</ConsigneePhone>" &_ "<ConsigneeEmail>vonderluft.andrew@Con-way.com</ConsigneeEmail>" &_ "</Consignee>" &_ "<Item>" &_ "<Quantity pkgtype=""PLT"">44</Quantity>" &_ "<Weight unit=""lbs"">667</Weight>" &_ "<Description>widget-arms</Description>" &_ "<CmdtyClass>775</CmdtyClass>" &_ "<NMFClass></NMFClass>" &_ "<HazMat>N</HazMat>" &_ "</Item>" &_ "<Item>" &_ "<Quantity pkgtype=""PCS"">11</Quantity>" &_ "<Weight unit=""lbs"">789</Weight>" &_ "<Description>cam-shafts</Description>" &_ "<CmdtyClass>100</CmdtyClass>" &_ "<NMFClass></NMFClass>" &_ "<HazMat>N</HazMat>" &_ "</Item>" &_ "<Accessorial chargecode=""P"">GUR</Accessorial>" &_ "<Accessorial chargecode=""C"">DID</Accessorial>" &_ "<Accessorial chargecode=""C"">DST</Accessorial>" &_ "<ShippingRemarks>TEST TEST TEST</ShippingRemarks>" &_ "<EmergencyContact></EmergencyContact>" &_ "<PickupRequest>" &_ "<PickupDate>" & today & "</PickupDate>" &_ "<PickupReadyTime>11:00 am</PickupReadyTime>" &_ "<DockCloseTime>7:00 pm</DockCloseTime>" &_ "<ContactName>Frank</ContactName>" &_ "<ContactCompany>Franklin Arms</ContactCompany>" &_ "<ContactPhone>(333)444-4321</ContactPhone>" &_ "</PickupRequest>" &_ "<SendBOLemail/>" &_ "</BOLrequest>" ' Convert characters to proper format for HTTP POST xmlRequest = Server.URLEncode(xmlRequest) '*Call Con-way XML Interface. ' The XMLHTTP classes used here are availible from Microsoft and ' are autmatically installed and registered with Internet Explorer. ' For more info on how to use these classes please see http://msdn.microsoft.com/xml/ set httpConn = Server.CreateObject("Microsoft.XMLHTTP") 'or alternately depending on what is installed on your server: 'set httpConn = Server.CreateObject("MSXML2.ServerXMLHTTP") 'or whatever parser you have installed ' open synchronous connection to X-ShipmentStatus httpConn.open "POST",conwayXmlUrl,false,username,password 'set post data type, and post data httpConn.setRequestHeader "Content-type","application/x-www-form-urlencoded" httpConn.Send requestType & "=" & xmlRequest '*Parse the response ' This example uses the MS XML DOM classes that ship with IE 5.5 or the XML SDK ' to create an XML document. Here we simple redisplay the XML data, but in a real ' world scenario you will parse the document to locate the data you wish to display ' or save, such as the net charge, transit time, and disclaimer. '*For more info on how to use the MS XML SDK please see ' http://msdn.microsoft.com/xml/index.asp ' If you need only the final net charge of the quote you might find it easier ' in some cases to use a simpler method such as 'InStr'. set xmlResponse = Server.CreateObject("Microsoft.XMLDOM") 'create XML DOM object 'or alternately, based on what is installed on your server: 'set shpResponse = Server.CreateObject("MSXML2.DOMDocument") set xmlResponse = httpConn.responseXML %> <html> <head> <title>Sample ASP for Con-way XML <%=title%></title> </head> <body text="Darkorange"> <center> <B><FONT face="Arial" size=+1><I>Sample ASP Con-way XML <%=title%></I></FONT></B> </center> <br> <b>This is the complete XML Response output for <%=title%>:</b> <br><br> <code><%=xmlResponse.xml%></code> <br><br> <b>This is the data for the elements (<%=myElement1%>,&nbsp;<%=myElement2%>) retrieved from the XML Response:</b> <br> <% 'Here is how to a value out of a specific XML element using MS XML: 'Get node lists of elements in the response with a given name set myElementList1 = xmlResponse.getElementsByTagName(myElement1) set myElementList2 = xmlResponse.getElementsByTagName(myElement2) 'Process the Nodelists as desired Dim i For i = 0 To (myElementList1.length - 1) response.write("<br><b>" & myElement1 & " = " & myElementList1.Item(i).Text &_ "<br>" & myElement2 & " = " & myElementList2.Item(i).Text & "</b>") Next %> </body> </html>