Ejemplo n.º 1
0
        private void AddShipToAddress(UPSTimeInTransit.TimeInTransitRequest request, bool isResidentialAddress)
        {
            var shipTo        = new UPSTimeInTransit.RequestShipToType();
            var shipToAddress = new UPSTimeInTransit.RequestShipToAddressType();

            if (!string.IsNullOrEmpty(ShipToCity))
            {
                shipToAddress.City = ShipToCity;
            }
            if (!string.IsNullOrEmpty(ShipToPostalCode))
            {
                shipToAddress.PostalCode = ShipToPostalCode;
            }
            if (!string.IsNullOrEmpty(ShipToStateProvinceCode))
            {
                shipToAddress.StateProvinceCode = ShipToStateProvinceCode;
            }
            if (!string.IsNullOrEmpty(ShipToCountryCode))
            {
                shipToAddress.CountryCode = ShipToCountryCode;
            }
            if (isResidentialAddress)
            {
                shipToAddress.ResidentialAddressIndicator = "true";
            }
            shipTo.Address = shipToAddress;
            request.ShipTo = shipTo;
        }
Ejemplo n.º 2
0
        public UPSTimeInTransit.TimeInTransitResponse CallUPSTimeInTransitRequest(int qty, int nrBoxes, string fullBoxWeight, string partialBoxWeight, string currencyCode, decimal unitPrice, bool isResidentialAddress)
        {
            var upsService = new UPSTimeInTransit.TimeInTransitService();
            var response   = new UPSTimeInTransit.TimeInTransitResponse();
            var request    = new UPSTimeInTransit.TimeInTransitRequest();

            AddUpsSecurity(upsService);
            var requestType = new UPSTimeInTransit.RequestType();

            String[] requestOption = { "TNT" };
            requestType.RequestOption = requestOption;
            request.Request           = requestType;
            AddShipFromAddress(request);
            AddShipToAddress(request, isResidentialAddress);
            PickupType pickup = new PickupType();

            pickup.Date    = DateTime.Now.ToString("yyyyMMdd");
            request.Pickup = pickup;
            var shipmentWeight = new UPSTimeInTransit.ShipmentWeightType();

            shipmentWeight.Weight = (nrBoxes * decimal.Parse(fullBoxWeight) + (string.IsNullOrEmpty(partialBoxWeight) ? 0 : decimal.Parse(partialBoxWeight))).ToString();//"10";
            var unitOfMeasurement = new UPSTimeInTransit.CodeDescriptionType();

            unitOfMeasurement.Code           = "LBS";
            unitOfMeasurement.Description    = "pounds";
            shipmentWeight.UnitOfMeasurement = unitOfMeasurement;
            request.ShipmentWeight           = shipmentWeight;

            request.TotalPackagesInShipment = nrBoxes.ToString();
            request.MaximumListSize         = "1";
            AddInvoiceTotalType(qty, unitPrice, currencyCode, request);

            var tntResponse = upsService.ProcessTimeInTransit(request);

            return(tntResponse);
        }
Ejemplo n.º 3
0
        private void AddShipFromAddress(UPSTimeInTransit.TimeInTransitRequest request)
        {
            var shipFrom        = new UPSTimeInTransit.RequestShipFromType();
            var shipFromAddress = new UPSTimeInTransit.RequestShipFromAddressType();

            if (!string.IsNullOrEmpty(ShipFromCity))
            {
                shipFromAddress.City = ShipFromCity;
            }
            if (!string.IsNullOrEmpty(ShipFromPostalCode))
            {
                shipFromAddress.PostalCode = ShipFromPostalCode;
            }
            if (!string.IsNullOrEmpty(ShipFromStateProvinceCode))
            {
                shipFromAddress.StateProvinceCode = ShipFromStateProvinceCode;
            }
            if (!string.IsNullOrEmpty(ShipFromCountryCode))
            {
                shipFromAddress.CountryCode = ShipFromCountryCode;
            }
            shipFrom.Address = shipFromAddress;
            request.ShipFrom = shipFrom;
        }
Ejemplo n.º 4
0
        private void AddInvoiceTotalType(int qty, decimal unitPrice, string currencyCode, UPSTimeInTransit.TimeInTransitRequest request)
        {
            var invoiceType = new UPSTimeInTransit.InvoiceLineTotalType();

            invoiceType.CurrencyCode = currencyCode;
            int total = (int)(qty * unitPrice);

            if (total % 100 > 0)
            {
                total = total + (100 - total % 100);
            }
            invoiceType.MonetaryValue = total.ToString();
            request.InvoiceLineTotal  = invoiceType;
        }
        public UPSTimeInTransit.TimeInTransitResponse CallUPSTimeInTransitRequest(int qty, int nrBoxes, string fullBoxWeight, string partialBoxWeight, string currencyCode, decimal unitPrice, bool isResidentialAddress)
        {
            var upsService = new UPSTimeInTransit.TimeInTransitService();
            var response = new UPSTimeInTransit.TimeInTransitResponse();
            var request = new UPSTimeInTransit.TimeInTransitRequest();
            AddUpsSecurity(upsService);
            var requestType = new UPSTimeInTransit.RequestType();
            String[] requestOption = { "TNT" };
            requestType.RequestOption = requestOption;
            request.Request = requestType;
            AddShipFromAddress(request);
            AddShipToAddress(request, isResidentialAddress);
            PickupType pickup = new PickupType();
            pickup.Date = DateTime.Now.ToString("yyyyMMdd");
            request.Pickup = pickup;
            var shipmentWeight = new UPSTimeInTransit.ShipmentWeightType();
            shipmentWeight.Weight = (nrBoxes * decimal.Parse(fullBoxWeight) + (string.IsNullOrEmpty(partialBoxWeight) ? 0 : decimal.Parse(partialBoxWeight))).ToString();//"10";
            var unitOfMeasurement = new UPSTimeInTransit.CodeDescriptionType();
            unitOfMeasurement.Code = "LBS";
            unitOfMeasurement.Description = "pounds";
            shipmentWeight.UnitOfMeasurement = unitOfMeasurement;
            request.ShipmentWeight = shipmentWeight;

            request.TotalPackagesInShipment = nrBoxes.ToString();
            request.MaximumListSize = "1";
            AddInvoiceTotalType(qty, unitPrice, currencyCode, request);

            var tntResponse = upsService.ProcessTimeInTransit(request);
            return tntResponse;
        }