示例#1
0
        private static void SetCustomDetails(RateRequest request)
        {
            request.RequestedShipment.EdtRequestType          = EdtRequestType.ALL;
            request.RequestedShipment.EdtRequestTypeSpecified = true;
            var customClearanceDetail = new CustomsClearanceDetail
            {
                //CustomsValue = new Money
                //{
                //    Amount = 100m,
                //    Currency = "USD",
                //    AmountSpecified = true
                //},
                DutiesPayment = new Payment
                {
                    PaymentType          = PaymentType.SENDER,
                    PaymentTypeSpecified = true
                },
                Commodities = new[]
                {
                    new Commodity
                    {
                        HarmonizedCode       = "392330100000",
                        Name                 = "Plastic Bottle",
                        Description          = "Plastic Bottle",
                        CountryOfManufacture = "CN",
                        Weight               = new Weight
                        {
                            Units = WeightUnits.LB,
                            Value = 2
                        },
                        Quantity      = 1,
                        QuantityUnits = "Number",
                        //UnitPrice = new Money
                        //{
                        //    Currency = "USD",
                        //    Amount = 100m
                        //},
                        CustomsValue = new Money
                        {
                            Currency        = "USD",
                            Amount          = 100m,
                            AmountSpecified = true
                        },
                        NumberOfPieces     = "1",
                        AdditionalMeasures = new [] { new Measure {
                                                          QuantitySpecified = false
                                                      } }
                    }
                },
                CommercialInvoice = new CommercialInvoice()
                {
                    FreightCharge =
                        new Money {
                        Amount = 100m, AmountSpecified = true, Currency = "USD"
                    }
                }
            };


            request.RequestedShipment.CustomsClearanceDetail = customClearanceDetail;
        }
        private CustomsClearanceDetail buildCustomClearanceSpec()
        {
            CustomsClearanceDetail spec = new CustomsClearanceDetail();

            spec.CommercialInvoice = new CommercialInvoice();
            spec.CommercialInvoice.Purpose = PurposeOfShipmentType.SOLD;
            spec.CommercialInvoice.PurposeSpecified = true;

            spec.DocumentContent = InternationalDocumentContentType.NON_DOCUMENTS;
            spec.DutiesPayment = new Payment();
            if (currentDespatch.ShippingAddressCountry == "CA")
            {
                spec.DutiesPayment.PaymentType = PaymentType.SENDER;
                spec.DutiesPayment.Payor = new Payor();
                spec.DutiesPayment.Payor.ResponsibleParty = shipper;
                spec.CommercialInvoice.TermsOfSale = "DDP";
            }
            else
            {
                spec.DutiesPayment.PaymentType = PaymentType.RECIPIENT;
                spec.CommercialInvoice.TermsOfSale = "DDU";
            }

            List<Commodity> items = new List<Commodity>();
            decimal desired = 9.0M/currentDespatch.Items.Length; // HAX
            decimal total = 0.0M;
            foreach(var item in currentDespatch.Items) {
                Commodity com = new Commodity();
                com.NumberOfPieces = item.QuantityOrdered;

                com.Description = item.ItemGroupName;
                if (string.IsNullOrEmpty(item.Attribute5))
                {
                    com.CountryOfManufacture = "BD";
                }
                else
                {
                    com.CountryOfManufacture = LookupCountryCode(item.Attribute5);
                }

                com.Weight = new Weight();
                com.Weight.Value = decimal.Parse(item.Weight);
                com.Weight.Units = WeightUnits.KG;

                com.Quantity = decimal.Parse(item.QuantityOrdered);
                com.QuantitySpecified = true;
                com.QuantityUnits = "EA";

                com.UnitPrice = new Money();
                //com.UnitPrice.Amount = decimal.Parse(item.SalePrice);
                com.UnitPrice.Amount = desired / com.Quantity; // HAX
                total += com.UnitPrice.Amount * com.Quantity;
                com.UnitPrice.Currency = "UKL";

                com.CustomsValue = com.UnitPrice;
                com.PartNumber = item.Barcode;

                items.Add(com);
            }

            spec.Commodities = items.ToArray();
            spec.CustomsValue = new Money();

            spec.CustomsValue.Amount = total;
            spec.CustomsValue.Currency = "UKL";

            return spec;
        }