⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uspsservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            <Days>1</Days>        </PriorityMailResponse>    Package Services: (API=StandardB)        Request:        <StandardBRequest USERID="xxxxxxx" PASSWORD="xxxxxxx">            <OriginZip>4</OriginZip>            <DestinationZip>4</DestinationZip>        </StandardBRequest>        Response:        <StandardBResponse>            <OriginZip>4</OriginZip>            <DestinationZip>4</DestinationZip>            <Days>2</Days>        </StandardBResponse>    Note:        When submitting ZIP codes, only the first 3 digits are used.        If a 1- or 2-digit ZIP code is entered, leading zeros are implied.        If a 4- or 5-digit ZIP code is entered, the last digits  will be ignored.    */    public static Map uspsPriorityMailStandard(DispatchContext dctx, Map context) {        context.put("serviceType", "PriorityMail");        return uspsServiceStandards(dctx, context);    }    public static Map uspsPackageServicesStandard(DispatchContext dctx, Map context) {        context.put("serviceType", "StandardB");        return uspsServiceStandards(dctx, context);    }    private static Map uspsServiceStandards(DispatchContext dctx, Map context) {        String type = (String) context.get("serviceType");        if (!type.matches("PriorityMail|StandardB")) {            return ServiceUtil.returnError("Unsupported service type: " + type);        }        Document requestDocument = createUspsRequestDocument(type + "Request");        UtilXml.addChildElementValue(requestDocument.getDocumentElement(), "OriginZip",                (String) context.get("originZip"), requestDocument);        UtilXml.addChildElementValue(requestDocument.getDocumentElement(), "DestinationZip",                (String) context.get("destinationZip"), requestDocument);        Document responseDocument = null;        try {            responseDocument = sendUspsRequest(type, requestDocument);        } catch (UspsRequestException e) {            Debug.log(e, module);            return ServiceUtil.returnError("Error sending request for USPS " + type + " Service Standards service: " +                    e.getMessage());        }        Map result = ServiceUtil.returnSuccess();        String days = UtilXml.childElementValue(responseDocument.getDocumentElement(), "Days");        if (UtilValidate.isEmpty(days)) {            return ServiceUtil.returnError("Incomplete response from USPS " + type + " Service Standards service: " +                    "no Days element found");        }        result.put("days", days);        return result;    }    /*    Domestic Rate Calculator Samples: (API=Rate)    Request:    <RateRequest USERID="xxxxxx" PASSWORD="xxxxxxx">        <Package ID="0">            <Service>Priority</Service>            <ZipOrigination>20770</ZipOrigination>            <ZipDestination>09021</ZipDestination>            <Pounds>5</Pounds>            <Ounces>1</Ounces>            <Container>None</Container>            <Size>Regular</Size>            <Machinable>False</Machinable>        </Package>    </RateRequest>    Response:    <RateResponse>        <Package ID="0">            <Service>Priority</Service>            <ZipOrigination>20770</ZipOrigination>            <ZipDestination>09021</ZipDestination>            <Pounds>5</Pounds>            <Ounces>1</Ounces>            <Container>None</Container>            <Size>REGULAR</Size>            <Machinable>FALSE</Machinable>            <Zone>3</Zone>            <Postage>7.90</Postage>            <RestrictionCodes>B-B1-C-D-U</RestrictionCodes>            <RestrictionDescription>            B. Form 2976-A is required for all mail weighing 16 ounces or more, with exceptions noted below.            In addition, mailers must properly complete required customs documentation when mailing any potentially            dutiable mail addressed to an APO or FPO regardless of weight. B1. Form 2976 or 2976-A is required.            Articles are liable for customs duty and/or purchase tax unless they are bona fide gifts intended for            use by military personnel or their dependents. C. Cigarettes and other tobacco products are prohibited.            D. Coffee is prohibited. U. Parcels must weigh less than 16 ounces when addressed to Box R.            </RestrictionDescription>        </Package>    </RateResponse>    */    public static Map uspsDomesticRate(DispatchContext dctx, Map context) {        Document requestDocument = createUspsRequestDocument("RateRequest");        Element packageElement = UtilXml.addChildElement(requestDocument.getDocumentElement(), "Package", requestDocument);        packageElement.setAttribute("ID", "0");        UtilXml.addChildElementValue(packageElement, "Service", (String) context.get("service"), requestDocument);        UtilXml.addChildElementValue(packageElement, "ZipOrigination", (String) context.get("originZip"), requestDocument);        UtilXml.addChildElementValue(packageElement, "ZipDestination", (String) context.get("destinationZip"), requestDocument);        UtilXml.addChildElementValue(packageElement, "Pounds", (String) context.get("pounds"), requestDocument);        UtilXml.addChildElementValue(packageElement, "Ounces", (String) context.get("ounces"), requestDocument);        String container = (String) context.get("container");        if (UtilValidate.isEmpty(container)) {            container = "None";        }        UtilXml.addChildElementValue(packageElement, "Container", container, requestDocument);        String size = (String) context.get("size");        if (UtilValidate.isEmpty(size)) {            size = "Regular";        }        UtilXml.addChildElementValue(packageElement, "Size", size, requestDocument);        String machinable = (String) context.get("machinable");        if (UtilValidate.isEmpty(machinable)) {            machinable = "False";        }        UtilXml.addChildElementValue(packageElement, "Machinable", machinable, requestDocument);        Document responseDocument = null;        try {            responseDocument = sendUspsRequest("Rate", requestDocument);        } catch (UspsRequestException e) {            Debug.log(e, module);            return ServiceUtil.returnError("Error sending request for USPS Domestic Rate Calculation service: " + e.getMessage());        }        Element respPackageElement = UtilXml.firstChildElement(responseDocument.getDocumentElement(), "Package");        if (respPackageElement == null) {            return ServiceUtil.returnError("Incomplete response from USPS Domestic Rate Calculation service: no Package element found");        }        Element respErrorElement = UtilXml.firstChildElement(respPackageElement, "Error");        if (respErrorElement != null) {            return ServiceUtil.returnError("The following error was returned by the USPS Domestic Rate Calculation service: " +                    UtilXml.childElementValue(respErrorElement, "Description"));        }        Map result = ServiceUtil.returnSuccess();        String zone = UtilXml.childElementValue(respPackageElement, "Zone");        if (UtilValidate.isEmpty(zone)) {            return ServiceUtil.returnError("Incomplete response from USPS Domestic Rate Calculation service: no Zone element found");        }        result.put("zone", zone);        String postage = UtilXml.childElementValue(respPackageElement, "Postage");        if (UtilValidate.isEmpty(postage)) {            return ServiceUtil.returnError("Incomplete response from USPS Domestic Rate Calculation service: no Postage element found");        }        result.put("postage", postage);        String restrictionCodes = UtilXml.childElementValue(respPackageElement, "RestrictionCodes");        if (UtilValidate.isNotEmpty(restrictionCodes)) {            result.put("restrictionCodes", restrictionCodes);        }        String restrictionDesc = UtilXml.childElementValue(respPackageElement, "RestrictionDescription");        if (UtilValidate.isNotEmpty(restrictionCodes)) {            result.put("restrictionDesc", restrictionDesc);        }        return result;    }    // Warning: I don't think the following 2 services were completed or fully tested - 2004.09.06 JFE    /* --- ShipmentRouteSegment services --------------------------------------------------------------------------- */    public static Map uspsUpdateShipmentRateInfo(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();        String shipmentId = (String) context.get("shipmentId");        String shipmentRouteSegmentId = (String) context.get("shipmentRouteSegmentId");        // ShipmentRouteSegment identifier - used in error messages        String srsKeyString = "[" + shipmentId + "," + shipmentRouteSegmentId + "]";        try {            GenericValue shipmentRouteSegment = delegator.findByPrimaryKey("ShipmentRouteSegment",                    UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId));            if (shipmentRouteSegment == null) {                return ServiceUtil.returnError("ShipmentRouteSegment " + srsKeyString + " not found");            }            // ensure the carrier is USPS            if (!"USPS".equals(shipmentRouteSegment.getString("carrierPartyId"))) {                return ServiceUtil.returnError("The Carrier for ShipmentRouteSegment " + srsKeyString + ", is not USPS");            }            // get the origin address            GenericValue originAddress = shipmentRouteSegment.getRelatedOne("OriginPostalAddress");            if (originAddress == null) {                return ServiceUtil.returnError("OriginPostalAddress not found for ShipmentRouteSegment [" +                        shipmentId + ":" + shipmentRouteSegmentId + "]");            }            if (!"USA".equals(originAddress.getString("countryGeoId"))) {                return ServiceUtil.returnError("ShipmentRouteSeqment " + srsKeyString + " does not originate from a US address");            }            String originZip = originAddress.getString("postalCode");            if (UtilValidate.isEmpty(originZip)) {                return ServiceUtil.returnError("ZIP code is missing from the origin postal address" +                        " (contactMechId " + originAddress.getString("contactMechId") + ")");            }            // get the destination address            GenericValue destinationAddress = shipmentRouteSegment.getRelatedOne("DestPostalAddress");            if (destinationAddress == null) {                return ServiceUtil.returnError("DestPostalAddress not found for ShipmentRouteSegment " + srsKeyString);            }            if (!"USA".equals(destinationAddress.getString("countryGeoId"))) {                return ServiceUtil.returnError("ShipmentRouteSeqment " + srsKeyString + " is not destined for a US address");            }            String destinationZip = destinationAddress.getString("postalCode");            if (UtilValidate.isEmpty(destinationZip)) {                return ServiceUtil.returnError("ZIP code is missing from the destination postal address" +                        " (contactMechId " + originAddress.getString("contactMechId") + ")");            }            // get the service type from the CarrierShipmentMethod            String shipmentMethodTypeId = shipmentRouteSegment.getString("shipmentMethodTypeId");            String partyId = shipmentRouteSegment.getString("carrierPartyId");            String csmKeystring = "[" + shipmentMethodTypeId + "," + partyId + ",CARRIER]";            GenericValue carrierShipmentMethod = delegator.findByPrimaryKey("CarrierShipmentMethod",                    UtilMisc.toMap("partyId", partyId, "roleTypeId", "CARRIER", "shipmentMethodTypeId", shipmentMethodTypeId));            if (carrierShipmentMethod == null) {                return ServiceUtil.returnError("CarrierShipmentMethod " + csmKeystring +                        " not found for ShipmentRouteSegment " + srsKeyString);            }            String serviceType = carrierShipmentMethod.getString("carrierServiceCode");            if (UtilValidate.isEmpty(serviceType)) {                return ServiceUtil.returnError("carrierServiceCode not found for CarrierShipmentMethod" + csmKeystring);            }            // get the packages for this shipment route segment            List shipmentPackageRouteSegList = shipmentRouteSegment.getRelated("ShipmentPackageRouteSeg", null,                    UtilMisc.toList("+shipmentPackageSeqId"));            if (UtilValidate.isEmpty(shipmentPackageRouteSegList)) {                return ServiceUtil.returnError("No packages found for ShipmentRouteSegment " + srsKeyString);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -