public final String toDSML(HPDInstanceModel hpd, HPDClientConfig config) {
        String baseDNOffset = new String();
        String dsmlScope = new String();
        switch (getSearchScope()) {
            case AllEntities:
                //Do Nothing for the offset, but the depth needs to be 2 levels
                dsmlScope = "wholeSubtree";
                break;
            case IndividualProvidersOnly:
                baseDNOffset = "ou=" + Constants.ENTITY_TYPE_INDIVIDUAL_RDN_OU + ",";
                dsmlScope = "singleLevel";
                break;

            case OrgsOnly:
                baseDNOffset = "ou=" + Constants.ENTITY_TYPE_ORG_RDN_OU + ",";
                dsmlScope = "singleLevel";
                break;
            case CredentialsOnly:
                baseDNOffset = "ou=" + Constants.ENTITY_TYPE_CREDENTIAL_RDN_OU + ",";
                dsmlScope = "singleLevel";
                break;
            case ProvidersAffiliatedToOrg:                
            case HasAProviderRelationshipsOnly:
            case HasAnOrgRelationshipsOnly:
                baseDNOffset = "ou=" + Constants.ENTITY_TYPE_RELATIONSHIP_RDN_OU + ",";
                dsmlScope = "singleLevel";
                break;
            case ServicesOnly:
                baseDNOffset = "ou=" + Constants.ENTITY_TYPE_SERVICE_RDN_OU + ",";
                dsmlScope = "singleLevel";
                break;                
            default:
                throw new RuntimeException("Unexpected SearchRequest searchScope: " + getSearchScope());
        }
        //Building the SoapRequest
        //Get the Current template we're going to use
        String requestBody = config.getSoapRequestTemplate();
        //We might need to store this later, we'll see...
        String soapActionRequestUUID = UUID.randomUUID().toString();
        //Generate an random requestId to use for the batchRequest and the searchRequest.  Keeping these the same for now.
        String randomRequestId = HPDUtil.generateRequestId();
        //Generate batchRequestID
        String batchRequestId = randomRequestId;
        //Generate searchRequestID
        String searchRequetID = randomRequestId;
        //Build the batchrequest, merging in the required dynamic aspects via String.format()
        String batchRequest = String.format(requestBody, soapActionRequestUUID, batchRequestId, String.format(searchRequestBody, baseDNOffset, hpd.getBaseDN(), dsmlScope, searchRequetID, toDSMLSearchString(hpd)));
        //If we need to tweak the request for an edge case, apply the XSLT to the rqeuest.
        if (HPDUtil.isNotBlank(hpd.getCustomHPDRequestXSLT())) {
            //Do the XSLT here on the request to conform to whatever honked request the destination needs..
            log.log(Level.FINE, "<<<< HPDRequestBody Transformed via custom XSLT");
            String xsltTransform = hpd.getCustomHPDRequestXSLT();
            log.log(Level.FINE, "PRE:\n{0}", batchRequest);
            batchRequest = XSLUtil.tranform(xsltTransform, batchRequest);
            log.log(Level.FINE, "POST:\n{0}", batchRequest);
        }
        return batchRequest;
    }