Click or drag to resize

Implementing the IRatingAdapter Interface

The rating adapter can be used to integrate external applications or services that provide shipment rating functionality.

Overview

Every rating adapter will have a main Rate() method that has an incoming ShipmentRequest object containing all of the shipment level and package level information needed to rate the shipment, as well as a list of services to rate the shipment against. This method is where the developer would implement the following steps:

  1. Convert the incoming ShipExec ShipmentRequest data to the required external format
  2. Establish a connection to the external service or application
  3. submit the rate request to the external service and receive the response data or capture any error messages
  4. Convert the returned rate response or error data into a ShipExec ShipmentResponse object so that it can be passed back to the ShipExec Application

Rate Request


The ShipmentRequest and ShipmentResponse objects contain the following elements:

Package Defaults

Contains all of the shipment-level details as well as the default package attributes to be used across all packages unless the attribute value is set at the package level

Packages

A list of one or more packages that contain all of the unique individual package-level attributes for the shipment

shipment Request
Interface Members

Click here for a list of all members of the IRatingAdapter interface.

Sample Implementation of IRatingAdapter

Configuration


Note Note

All Adapters must have this configuration interface implemented in order for the adapter to function. See IAdapterConfigurationProvider for a sample implementation of IAdapterConfigurationProvider.


Implementation


Below is a sample implementation of IRatingAdapter

C#
using System;
using System.Collections.Generic;
using PSI.Sox;
using PSI.Sox.Adapter.Interfaces;
using PSI.Sox.Interfaces;

namespace MockRatingAdapter
{
    public class Rating : IRatingAdapter
    {

        private  string _adapterName = "PSI Mock Rating Adapter";
        private  string _adapterSymbol = "PSI.SOX.MOCKRATING";


        public string AdapterSymbol
        {
            get { return _adapterSymbol; }
        }

        public Version AdapterVersion
        {
            get { return new Version("1.1"); }
        }

        public Guid AdapterId
        {
            get { return new Guid("499D90A8-E074-48D9-86F5-B9XXXXXXXXX"); }
        }

        public string CompanyName
        {
            get { return "Shipping Services Inc"; }
        }

        public IAdapterConfiguration AdapterConfiguration { get; set; }

        public string AdapterName
        {
            get { return _adapterName; }
        }

        public ILogger Logger { get; set; }

        public IProxySettings ProxySettings { get; set; }

        public List<ShipmentResponse> Rate(ShipmentRequest shipmentRequest, List<string> services, int sortOrder)
        {
            #region ShipmentResponse XML

            var shipmentResponseXml1 =
@"<ShipmentResponse xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" >
       <def_attr>
    <error_code>0</error_code>
    <error_message>No error</error_message>
    <base_charge>8.81</base_charge>
    <base_charge_unit>USD</base_charge_unit>
    <bundle_id_list>
      <long>31460</long>
    </bundle_id_list>
    <service>UPS Ground</service>
    <subcategory>CONNECTSHIP_UPS.UPS.GND</subcategory>
    <time_in_transit>FOREVER</time_in_transit>
    <total>8.81</total>
    <total_unit>USD</total_unit>
    <time_in_transit_days>-1</time_in_transit_days>
    <arrive_time>23:59:59</arrive_time>
  </def_attr>
  <packages>
    <PackageResponse>
      <error_code>0</error_code>
      <error_message>No error</error_message>
      <apportioned_base>8.81</apportioned_base>
      <apportioned_base_unit>USD</apportioned_base_unit>
      <apportioned_total>8.81</apportioned_total>
      <apportioned_total_unit>USD</apportioned_total_unit>
      <bar_code>1Z1111110300003673</bar_code>
      <bundle_id>31460</bundle_id>
      <dimensional_weight_rated>true</dimensional_weight_rated>
      <maxicode>
        <string>171040000</string>
        <string>840</string>
        <string>003</string>
        <string>1Z00003673</string>
        <string>UPSN</string>
        <string>111111</string>
        <string>258</string>
        <string />
        <string>1/1</string>
        <string>1</string>
        <string>N</string>
        <string>1821 S 19TH ST</string>
        <string>HARRISBURG</string>
        <string>PA</string>
        <string>2ND FLOOR</string>
        <string />
        <string>TEST COMPANY</string>
        <string>GEORGE WASHINGTON</string>
      </maxicode>
      <msn>49110</msn>
      <nofn_sequence_bundle>1</nofn_sequence_bundle>
      <nofn_total_bundle>1</nofn_total_bundle>
      <package_list_id>26862</package_list_id>
      <rated_weight>7</rated_weight>
      <rated_weight_unit>wuLb</rated_weight_unit>
      <routing_code> PA 171 9-20</routing_code>
      <service>UPS Ground</service>
      <subcategory>CONNECTSHIP_UPS.UPS.GND</subcategory>
      <time_in_transit>FOREVER</time_in_transit>
      <tracking_number>1Z1111110300003673</tracking_number>
      <zone>2</zone>
      <time_in_transit_days>-1</time_in_transit_days>
      <arrive_time>23:59:59</arrive_time>
      <documents />
      <global_msn>13754</global_msn>
      <global_bundle_id>12912</global_bundle_id>
      <ship_id>12830</ship_id>
    </PackageResponse>
  </packages>
</ShipmentResponse>";

            var shipmentResponseXml2 =
@"<ShipmentResponse xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" >
       <def_attr>
    <error_code>0</error_code>
    <error_message>No error</error_message>
    <base_charge>8.81</base_charge>
    <base_charge_unit>USD</base_charge_unit>
    <bundle_id_list>
      <long>31460</long>
    </bundle_id_list>
    <service>UPS Ground</service>
    <subcategory>CONNECTSHIP_UPS.UPS.GND</subcategory>
    <time_in_transit>FOREVER</time_in_transit>
    <total>8.81</total>
    <total_unit>USD</total_unit>
    <time_in_transit_days>-1</time_in_transit_days>
    <arrive_time>23:59:59</arrive_time>
  </def_attr>
  <packages>
    <PackageResponse>
      <error_code>0</error_code>
      <error_message>No error</error_message>
      <apportioned_base>8.81</apportioned_base>
      <apportioned_base_unit>USD</apportioned_base_unit>
      <apportioned_total>8.81</apportioned_total>
      <apportioned_total_unit>USD</apportioned_total_unit>
      <bar_code>1Z1111110300003673</bar_code>
      <bundle_id>31460</bundle_id>
      <dimensional_weight_rated>true</dimensional_weight_rated>
      <maxicode>
        <string>171040000</string>
        <string>840</string>
        <string>003</string>
        <string>1Z00003673</string>
        <string>UPSN</string>
        <string>111111</string>
        <string>258</string>
        <string />
        <string>1/1</string>
        <string>1</string>
        <string>N</string>
        <string>1821 S 19TH ST</string>
        <string>HARRISBURG</string>
        <string>PA</string>
        <string>2ND FLOOR</string>
        <string />
        <string>TEST COMPANY</string>
        <string>GEORGE WASHINGTON</string>
      </maxicode>
      <msn>49110</msn>
      <nofn_sequence_bundle>1</nofn_sequence_bundle>
      <nofn_total_bundle>1</nofn_total_bundle>
      <package_list_id>26862</package_list_id>
      <rated_weight>7</rated_weight>
      <rated_weight_unit>wuLb</rated_weight_unit>
      <routing_code> PA 171 9-20</routing_code>
      <service>UPS Ground</service>
      <subcategory>CONNECTSHIP_UPS.UPS.GND</subcategory>
      <time_in_transit>FOREVER</time_in_transit>
      <tracking_number>1Z1111110300003673</tracking_number>
      <zone>2</zone>
      <time_in_transit_days>-1</time_in_transit_days>
      <arrive_time>23:59:59</arrive_time>
      <documents />
      <global_msn>13755</global_msn>
      <global_bundle_id>12912</global_bundle_id>
      <ship_id>12830</ship_id>
    </PackageResponse>
  </packages>
</ShipmentResponse>";

            #endregion

            return new List<ShipmentResponse> {
                ShipmentResponse.CreateShipmentResponse(shipmentResponseXml1),
                ShipmentResponse.CreateShipmentResponse(shipmentResponseXml2)
            };
        }

        public void Dispose()
        {
        }

        public void Init()
        {
        }
    }
}