ASP example

This is developer level content. The toolkit itself is available on the Downloads page.

See Toolkit - Install and Toolkit - Create for general information that will set the context for using this particular example.

The ASP example is based on an ASP file named: Custom Rate Engine.asp which is used to create a simple web application able to handle Pierbridge Rate Requests and generate rates accordingly. This solution can be modified to match the requirements of each project. The solution consists of following files:

  • CustomRateEngine.asp
  • LogFile.asp
  • Web.config

The CustomRateEngine.asp consists of the main logic of the Custom Rate Engine. Without any modifications the rate engine will receive a request from the product, which includes the Pierbridge Rate Request, pull out some most commonly used parameters and create a Pierbridge Rate Response based around the rating logic as a http response to each request. This includes accessing elements in the Pierbridge Response.

Access request properties

Pierbridge Rate Request data may be stored in a number of CustomRateParameters which provide an easy access to each individual field through a property. Currently, the example does a lookup on the request as follows:

Dim objXML 

Set objXML = Server.CreateObject("Microsoft.XMLDOM")	
objXML.LoadXml(Request.Form)
	
SET insuranceTypeNode = objXML.documentElement.selectSingleNode("Packages/Package/Insurance/Type")

If Not (insuranceTypeNode Is Nothing) And insuranceTypeNode.Text <> "" Then 
  If Cint(insuranceTypeNode.Text) > 0 Then
    accessorialCharge = accessorialCharge + insuranceCharge
  End If 
End If

Access response properties

Top

The Pierbridge Rate or Ship Response is present as a child of the root element. This xml contains the data returned from the carrier, such as rates, zone etc., in the Pierbridge format.

Dim zoneNode, zone
Set zoneNode = objXML.documentElement.selectSingleNode("/*/PierbridgeRateResponse/Zone")

if (Not zoneNode Is Nothing) And zoneNode.Text <> "" Then
  zone = zoneNode.Text
End If

The rates returned by the carrier can be accessed via a list property named CarrierRates:

Dim rateNode
Set rateNode = objXML.documentElement.selectSingleNode("/*/PierbridgeRateResponse/Rates/Rate[0]")
If Not rateNode Is Nothing Then
  ' Get Shipping Charge (ie with ChargeGroupType=3) retuned by Carrier and use in custom rate
  Dim baseChargeNode
  Set baseChargeNode = rateNode.selectSingleNode("ChargeGroups/ChargeGroup[ChargeGroupType=3]/ChargeGroupValue")
  If Not (baseChargeNode Is Nothing) And baseChargeNode.Text <> "" Then 
    baseRate = Cdbl(baseChargeNode.Text)
  End If 
End If

Create Pierbridge Rate Response

Top

Any response file manipulation has been done by using a simple string builder to demonstrate the context and in order to keep the example code easy to read.

Based on the simple logic present for rating the response is generated:

Dim response

response = response & "<?xml version=""1.0"" encoding=""UTF-8""?>"
response = response & "<PierbridgeRateResponse xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">"
  …
response = response & "</Package></Packages></PierbridgeRateResponse>"

Response.write(response)

It is important to match the rate type node with the rate engine custom rate.

Rates are inserted appropriately within the response structure:

'chargegroups'
 response = response & "<ChargeGroups>"
'chargegroup - accessorials'
 response = response & "<ChargeGroup>"
 response = response & "<ChargeGroupType>1</ChargeGroupType>"
 response = response & "<ChargeGroupDescription>Accessorial Charges</ChargeGroupDescription>"
 response = response & "<ChargeGroupValue>" & accessorialCharge & "</ChargeGroupValue>"
 response = response & "<ChargeGroupCurrency>USD</ChargeGroupCurrency>"
 'charges - cod'
 response = response & "<Charges><Charge>"
 response = response & "<ChargeType>3</ChargeType>"
 response = response & "<ChargeDescription>COD Charge</ChargeDescription>"
 response = response & "<ChargeValue>" & codCharge & "</ChargeValue>"
 response = response & "<ChargeGroupCurrency>USD</ChargeGroupCurrency>"
 response = response & "</Charge>"
 'charges - total accessorials'
 response = response & "<Charge>"
 response = response & "<ChargeType>15</ChargeType>"
 response = response & "<ChargeDescription>Total Accesorial Charge</ChargeDescription>"
 response = response & "<ChargeValue>" & accessorialCharge & "</ChargeValue>"
 response = response & "<ChargeGroupCurrency>USD</ChargeGroupCurrency>"
 response = response & "</Charge></Charges>"
 response = response & "</ChargeGroup>"

See Charge Types and Charge Base Types for listings from the Transtream database.

Error logging

Top

The rate engine uses a log file for error logging in case any error occurs. If logging is enabled, the error messages are written in a log file. The error log path is configured in the LogFile.asp.

Error messages are customizable and can be changed:

Call LogFile(“Custom Error Message.”)
Article last edited 20 July 2017