code: public static BoxRetentionPolicyAssignment.Info createAssignmentToMetadata(BoxAPIConnection api,
                                                                                 String policyID,
                                                                                 String templateID,
                                                                                 MetadataFieldFilter... filter) {
          JsonObject assignTo = new JsonObject().add("type", TYPE_METADATA).add("id", templateID);
          JsonArray filters = null;
          if (filter.length > 0) {
              filters = new JsonArray();
              for (MetadataFieldFilter f : filter) {
                  filters.add(f.getJsonObject());
              }
          }
          return createAssignment(api, policyID, assignTo, filters);
      }
docs: Assigns a retention policy to all items with a given metadata template, optionally matching on fields.
  @param api the API connection to be used by the created assignment.
  @param policyID id of the assigned retention policy.
  @param templateID the ID of the metadata template to assign the policy to.
  @param filter optional fields to match against in the metadata template.
  @return info about the created assignment.