Click or drag to resize

Implementing the IPackPlanningAdapter Interface

The Pack Planning adapter can be used to run custom code to calculate the optimal packing arrangement based on item and container dimensions.

Interface Members

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

Sample Implementation of IPackPlanningAdapter

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 IPackPlanningAdapter

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

namespace MockPackPlanning
{
    public class PackPlanning: IPackPlanningAdapter
    {

        private string _adapterName = "PSI Mock Pack Planning";

        /// <summary>
        /// 
        /// </summary>
        /// <param name="packingRequest"></param>
        /// <returns></returns>
        public PSI.Sox.Packing.PackingAdapterResponse Pack(PSI.Sox.Packing.PackingAdapterRequest packingRequest)
        {

            PSI.Sox.Packing.PackingAdapterResponse result = new PSI.Sox.Packing.PackingAdapterResponse();

            result.ErrorCode = 0;
            result.OrderReference = packingRequest.OrderReference;
            result.Packs = new List<PSI.Sox.Packing.Packing>();

            if (packingRequest.AvailableContainers != null && packingRequest.AvailableContainers.Any())
            {

                foreach (var container in packingRequest.AvailableContainers)
                {
                    PSI.Sox.Packing.Packing packing = new PSI.Sox.Packing.Packing();
                    packing.Container = container;
                    packing.CubeUtilization = 20;
                    packing.ItemVolume = 20;
                    packing.OrderLines = packingRequest.OrderLines;
                    packing.TotalWeight = new PSI.Sox.Weight { Amount = 10.9, Units = "LB" };

                    result.Packs.Add(packing);

                }
            }
            else if (AvailableContainers != null && AvailableContainers.Any())
            {
                foreach (var container in AvailableContainers)
                {
                    PSI.Sox.Packing.Packing packing = new PSI.Sox.Packing.Packing();
                    packing.Container = container;
                    packing.CubeUtilization = 20;
                    packing.ItemVolume = 20;
                    packing.OrderLines = packingRequest.OrderLines;
                    packing.TotalWeight = new PSI.Sox.Weight { Amount = 10.9, Units = "LB" };

                    result.Packs.Add(packing);

                }

            }
            else
            {
                throw new Exception("No Conatiners supplied for packing.");

            }

            return result;

        }

        /// <summary>
        /// 
        /// </summary>
        public List<PSI.Sox.Packing.Container> AvailableContainers { get; set;}

        /// <summary>
        /// 
        /// </summary>
        public Version AdapterVersion
        {
            get { return new Version("1.1"); }
        }

        /// <summary>
        /// 
        /// </summary>
        public Guid AdapterId
        {
            get { return new Guid("7D777304-77FD-445C-BD12-XXXXXXXXXXXX"); }
        }

        /// <summary>
        /// 
        /// </summary>
        public string CompanyName
        {
            get { return "Shipping Services Inc"; }
        }

        /// <summary>
        /// 
        /// </summary>
        public void Dispose()
        {
            //unload any open objects
        }

        public void Init()
        {
            throw new NotImplementedException();
        }

        public string AdapterSymbol
        {
            get { return _adapterName; }
        }

        public IAdapterConfiguration AdapterConfiguration { get; set; }

        public string AdapterName
        {
            get { return _adapterName; }
        }

        public ILogger Logger { get; set; }

        public IProxySettings ProxySettings { get; set; }
    }
}

Sample Implementation of IPackPlanningAdapter

Configuration

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

Implementation

Below is a sample implementation of the IPackPlanningAdapter

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

namespace MockPackPlanning
{
    public class PackPlanning : IPackPlanningAdapter
    {
        private string _adapterName = "PSI Mock Pack Planning";

        /// <summary>
        /// 
        /// </summary>
        /// <param name="packingRequest"></param>
        /// <returns></returns>
        public PSI.Sox.Packing.PackingAdapterResponse Pack(PSI.Sox.Packing.PackingAdapterRequest packingRequest)
        {
            var result = new PSI.Sox.Packing.PackingAdapterResponse();

            result.ErrorCode = 0;
            result.OrderReference = packingRequest.OrderReference;
            result.Packs = new List<PSI.Sox.Packing.Packing>();

            if (packingRequest.AvailableContainers != null && packingRequest.AvailableContainers.Any())
                foreach (var container in packingRequest.AvailableContainers)
                {
                    var packing = new PSI.Sox.Packing.Packing();
                    packing.Container = container;
                    //pack.additional_information = ??;
                    packing.CubeUtilization = 20;
                    packing.ItemVolume = 20;
                    packing.OrderLines = packingRequest.OrderLines;
                    packing.TotalWeight = new PSI.Sox.Weight {Amount = 10.9, Units = "LB"};

                    result.Packs.Add(packing);
                }
            else if (AvailableContainers != null && AvailableContainers.Any())
                foreach (var container in AvailableContainers)
                {
                    var packing = new PSI.Sox.Packing.Packing();
                    packing.Container = container;
                    //pack.additional_information = ??;
                    packing.CubeUtilization = 20;
                    packing.ItemVolume = 20;
                    packing.OrderLines = packingRequest.OrderLines;
                    packing.TotalWeight = new PSI.Sox.Weight {Amount = 10.9, Units = "LB"};

                    result.Packs.Add(packing);
                }
            else
                throw new Exception("No Conatiners supplied for packing.");

            //result.ErrorCode = 30000;
            //result.ErrorMessage = "No Conatiners supplied for packing.";

            return result;
        }

        /// <summary>
        /// 
        /// </summary>
        public List<PSI.Sox.Packing.Container> AvailableContainers { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public Version AdapterVersion => new Version("1.1");

        /// <summary>
        /// 
        /// </summary>
        public Guid AdapterId => new Guid("7D777304-77FD-445C-BD12-891FCA838B4F");

        /// <summary>
        /// 
        /// </summary>
        public string CompanyName => "UPS Professional Services Inc";

        /// <summary>
        /// 
        /// </summary>
        public void Dispose()
        {
            //unload any open objects
        }

        public void Init()
        {
            throw new NotImplementedException();
        }

        public string AdapterSymbol => _adapterName;

        public IAdapterConfiguration AdapterConfiguration { get; set; }

        public string AdapterName => _adapterName;

        public ILogger Logger { get; set; }

        public IProxySettings ProxySettings { get; set; }
    }
}