Esempio n. 1
0
        public void RejectedParcelTest()
        {
            ParcelDimension parcelDimension = new ParcelDimension(110, 20, 55, 120);

            var actualResult = Processor.GetParcelDeliveryCost(parcelDimension.Weight, parcelDimension.Height, parcelDimension.Width, parcelDimension.Depth);

            string expectedResult = "N/A";

            Assert.AreEqual(expectedResult, actualResult.Item2);
        }
        /// <summary>
        /// Get and validate inputs and create object Parcel Dimension to pass for cost calculation
        /// </summary>
        /// <param name="weight"></param>
        /// <param name="height"></param>
        /// <param name="width"></param>
        /// <param name="depth"></param>
        /// <returns></returns>
        public static Tuple <string, string> GetParcelDeliveryCost(int weight, int height, int width, int depth)
        {
            if (!Validator.IsValidValue(weight) || !Validator.IsValidValue(height) || !Validator.IsValidValue(width) || !Validator.IsValidValue(depth))
            {
                throw new System.Exception("Values cannot be less than 0");
            }

            var parcelDimension = new ParcelDimension(weight, height, width, depth);

            return(CalculateParcelDeliveryCost(parcelDimension));
        }
Esempio n. 3
0
        public void SmallParcelTest()
        {
            ParcelDimension parcelDimension = new ParcelDimension(2, 3, 10, 12);

            int expectedResult = 18;

            Calculator calculator = new Calculator();

            int actualResult = calculator.Calculate(parcelDimension.Volume, new SmallParcel());

            Assert.AreEqual(expectedResult, actualResult);
        }
Esempio n. 4
0
        public void MediumParcelTest()
        {
            ParcelDimension parcelDimension = new ParcelDimension(10, 20, 5, 20);

            int expectedResult = 80;

            Calculator calculator = new Calculator();

            int actualResult = calculator.Calculate(parcelDimension.Volume, new MediumParcel());

            Assert.AreEqual(expectedResult, actualResult);
        }
Esempio n. 5
0
        public void LargeParcelTest()
        {
            ParcelDimension parcelDimension = new ParcelDimension(8, 20, 5, 50);

            int expectedResult = 150;

            Calculator calculator = new Calculator();

            int actualResult = calculator.Calculate(parcelDimension.Volume, new LargeParcel());

            Assert.AreEqual(expectedResult, actualResult);
        }
Esempio n. 6
0
        public void HeavyParcelTest()
        {
            ParcelDimension parcelDimension = new ParcelDimension(22, 5, 5, 5);

            int expectedResult = 330;

            Calculator calculator = new Calculator();

            int actualResult = calculator.Calculate(parcelDimension.Weight, new HeavyParcel());

            Assert.AreEqual(expectedResult, actualResult);
        }
Esempio n. 7
0
        public IParcel GetParcel(int weight, int height, int width, int depth)
        {
            var dimension = new ParcelDimension(weight, height, width, depth);

            if (weight > 50)
            {
                return(new RejectParcel());
            }
            else if (weight > 10)
            {
                return(new HeavyParcel(new CostByWeightCalculator(), dimension));
            }
            else if (dimension.Volumn < 1500)
            {
                return(new SmallParcel(new CostByVolumnCalculator(), dimension));
            }
            else if (dimension.Volumn < 2500)
            {
                return(new MediumParcel(new CostByVolumnCalculator(), dimension));
            }

            return(new LargeParcel(new CostByVolumnCalculator(), dimension));
        }
        /// <summary>
        /// Implementaion of business rules to get parcel category and calculate parcel delivery cost
        /// </summary>
        /// <param name="parcelDimension"></param>
        /// <returns></returns>

        private static Tuple <string, string> CalculateParcelDeliveryCost(ParcelDimension parcelDimension)
        {
            if (parcelDimension.Weight > 50)
            {
                return(Tuple.Create(CategoryTypes.Rejected.ToString(), "N/A"));
            }


            using (Calculator calculator = new Calculator())
            {
                int    cost     = 0;
                string category = string.Empty;

                if (parcelDimension.Weight > 10)
                {
                    cost     = calculator.Calculate(parcelDimension.Weight, new HeavyParcel());
                    category = CategoryTypes.Heavy.ToString();
                }
                else if (parcelDimension.Volume < 1500)
                {
                    cost     = calculator.Calculate(parcelDimension.Volume, new SmallParcel());
                    category = CategoryTypes.Small.ToString();
                }
                else if (parcelDimension.Volume < 2500)
                {
                    cost     = calculator.Calculate(parcelDimension.Volume, new MediumParcel());
                    category = CategoryTypes.Medium.ToString();
                }
                else
                {
                    cost     = calculator.Calculate(parcelDimension.Volume, new LargeParcel());
                    category = CategoryTypes.Large.ToString();
                }

                return(Tuple.Create(category + " Parcel", "$" + cost.ToString()));
            }
        }
        public void BasicRate()
        {
            List <string> fromAddressLine = new List <string>()
            {
                "8445 Graves Ave #25"
            };

            List <string> toAddressLine = new List <string>()
            {
                "10553 KERRIGAN Ct"
            };

            Address fromAddress = new Address
            {
                AddressLines  = fromAddressLine,
                Email         = "*****@*****.**",
                CityTown      = "Santee",
                Name          = "X X",
                CountryCode   = "US",
                PostalCode    = "92071",
                StateProvince = "CA",
            };

            Address toAddress = new Address
            {
                AddressLines  = toAddressLine,
                Email         = "*****@*****.**",
                CityTown      = "Santee",
                Name          = "X",
                CountryCode   = "US",
                PostalCode    = "92071",
                StateProvince = "CA",
            };


            ParcelDimension parcelDimension = new ParcelDimension
            {
                Height            = 1,
                Length            = 1,
                Width             = 1,
                UnitOfMeasurement = UnitOfDimension.IN
            };

            ParcelWeight parcelWeight = new ParcelWeight
            {
                UnitOfMeasurement = UnitOfWeight.OZ,
                Weight            = 1
            };

            Parcel parcel = new Parcel
            {
                CurrencyCode = "US",
                Dimension    = parcelDimension,
                Weight       = parcelWeight
            };

            Rates rates = new Rates
            {
                Carrier    = Carrier.USPS,
                ParcelType = ParcelType.LGENV
            };

            Shipment shipment = new Shipment
            {
                FromAddress = fromAddress,
                ToAddress   = toAddress,
                Parcel      = parcel,
                Rates       = new List <Rates> {
                    rates
                }
            };

            try
            {
                // Get rates
                ShippingApiResponse shippingApiResponse = Api.Rates(shipment).Result;
            }
            catch (Exception)
            {
                throw;
            }
        }
        static void Main(string[] args)
        {
            Configuration.Default.BasePath = "https://shipping-api-sandbox.pitneybowes.com/shippingservices";

            Configuration.Default.OAuthApiKey = "<API_KEY_REPLACE>";
            Configuration.Default.OAuthSecret = "<API_SECRET_REPLACE>";



            DateTime dt = DateTime.Now;

            var apiInstance              = new ShipmentApi(Configuration.Default);
            var xPBTransactionId         = dt.Millisecond.ToString(); // string | Required. A unique identifier for the transaction, up to 25 characters.
            var xPBUnifiedErrorStructure = true;                      // bool? | Set this to true to use the standard [error object](https://shipping.pitneybowes.com/reference/error-object.html#standard-error-object) if an error occurs. (optional)  (default to true)
            var xPBIntegratorCarrierId   = "898644";                  // string | USPS Only. Negotiated services rate, if applicable. (optional)

            //var xPBShipperRatePlan = xPBShipperRatePlan_example;  // string | USPS Only. Shipper rate plan, if applicable. For more information, see [this FAQ](https://shipping.pitneybowes.com/faqs/rates.html#rate-plans-faq). (optional)
            //var xPBShipmentGroupId = xPBShipmentGroupId_example;  // string |  **[Required parameter for PBPresort service](https://shipping.pitneybowes.com/api/post-shipments-presort.html)**.The job number that represents the agreement between the merchant and PB Presort. This was provided by Pitney Bowes during [merchant onboarding for PB Presort](https://shipping.pitneybowes.com/carriers/pb-presort.html). (optional)
            //var xPBShipperCarrierAccountId = xPBShipperCarrierAccountId_example;  // string | **[Required parameter for PBPresort service](https://shipping.pitneybowes.com/api/post-shipments-presort.html)**. The merchant's Mailer ID (MID), as provided by Pitney Bowes during merchant onboarding for PB Presort. (optional)
            //var includeDeliveryCommitment = includeDeliveryCommitment_example;  // string | If set to true, returns estimated transit times in days. Only for USPS Create Shipment. See also [Pitney Bowes Delivery Guarantee](https://shipping.pitneybowes.com/faqs/delivery-guarantee.html) [Do all USPS services return transit times?](https://shipping.pitneybowes.com/faqs/shipments.html#transit-times-faq) (optional)

            try
            {
                var           name1         = "Paul Wright";
                var           phone1        = "203-555-1430";
                var           email1        = "*****@*****.**";
                var           residential1  = false;
                List <string> addressLines1 = new List <string>()
                {
                    "27 Waterview Dr"
                };
                var cityTown1      = "Shelton";
                var stateProvince1 = "CT";
                var postalCode1    = "06484-4361";
                var countryCode1   = "US";
                var carrierRoute1  = "C010";
                var deliveryPoint1 = "27";
                var company1       = "Pitney Bowes Inc.";



                Address fromAddress = new Address(name: name1, phone: phone1, residential: residential1, addressLines: addressLines1, cityTown: cityTown1, stateProvince: stateProvince1, postalCode: postalCode1,
                                                  countryCode: countryCode1, carrierRoute: carrierRoute1, deliveryPoint: deliveryPoint1, company: company1, email: email1);


                var           name2         = "Rufous Sirius Canid";
                var           phone2        = "323 555-1212";
                var           email2        = "*****@*****.**";
                var           residential2  = true;
                List <string> addressLines2 = new List <string>()
                {
                    "631 S Main St"
                };
                var cityTown2      = "Greenville";
                var stateProvince2 = "SC";
                var postalCode2    = "29601";
                var countryCode2   = "US";

                var company2 = "ABC Company";

                Address toAddress = new Address(name: name2, phone: phone2, residential: residential2, addressLines: addressLines2, cityTown: cityTown2, stateProvince: stateProvince2, postalCode: postalCode2,
                                                countryCode: countryCode2, company: company2, email: email2);



                //Parcel
                ParcelDimension parcelDimension = new ParcelDimension();
                parcelDimension.Height            = 6.000m;
                parcelDimension.Length            = 6.000m;
                parcelDimension.Width             = 6.000m;
                parcelDimension.UnitOfMeasurement = UnitOfDimension.IN;

                ParcelWeight parcelWeight = new ParcelWeight(38.00m, UnitOfWeight.OZ);

                Parcel parcel = new Parcel(parcelDimension, parcelWeight);



                //Rates
                //Specil Service
                SpecialService specialService = new SpecialService(specialServiceId: "DelCon", inputParameters: new List <Parameter> {
                    new Parameter("INPUT_VALUE", "0")
                });
                Rate rate = new Rate(carrier: Carrier.USPS, serviceId: Services.PM, parcelType: ParcelType.PKG, specialServices: new List <SpecialService>()
                {
                    specialService
                }, inductionPostalCode: "06484");



                //Documents
                Document document = new Document(type: "SHIPPING_LABEL", contentType: Document.ContentTypeEnum.URL, size: Document.SizeEnum._4X6, fileFormat: Document.FileFormatEnum.PDF, printDialogOption: Document.PrintDialogOptionEnum.NOPRINTDIALOG);

                //ShipemntOptions
                List <Parameter> shipmentoption = new List <Parameter> {
                    new Parameter("SHIPPER_ID", "9025037569"), new Parameter("ADD_TO_MANIFEST", "true"), new Parameter("HIDE_TOTAL_CARRIER_CHARGE", "true"), new Parameter("PRINT_CUSTOM_MESSAGE_1", "custom message for label"), new Parameter("SHIPPING_LABEL_RECEIPT", "NO_OPTIONS")
                };


                var shipment = new Shipment(fromAddress: fromAddress, toAddress: toAddress, parcel: parcel, rates: new List <Rate>()
                {
                    rate
                }, documents: new List <Document>()
                {
                    document
                }, shipmentOptions: shipmentoption);                                                                                                                                                                     // Shipment | request



                // This operation creates a shipment and purchases a shipment label.
                Shipment result = apiInstance.CreateShipmentLabel(xPBTransactionId, shipment, xPBUnifiedErrorStructure, xPBIntegratorCarrierId);

                // Console.WriteLine((new System.Collections.Generic.ICollectionDebugView<shippingapi.Model.Document>(result.Documents).Items[0]).Contents);
                Console.WriteLine(result.Documents[0].Contents);
            }
            catch (ApiException e)
            {
                Debug.Print("Exception when calling ShipmentApi.CreateShipmentLabel: " + e.Message);
                Debug.Print("Status Code: " + e.ErrorCode);
                Debug.Print(e.StackTrace);
            }
        }