code: public static void runExample(
        AdManagerServices adManagerServices,
        AdManagerSession session,
        long customTargetingKeyId1,
        long customTargetingKeyId2)
        throws RemoteException {
  
      // Get the ContentMetadataKeyHierarchy service.
      ContentMetadataKeyHierarchyServiceInterface contentMetadataKeyHierarchyService =
          adManagerServices.get(session, ContentMetadataKeyHierarchyServiceInterface.class);
  
      List<ContentMetadataKeyHierarchyLevel> hierarchyLevels = new ArrayList<>();
      
      ContentMetadataKeyHierarchyLevel hierarchyLevel1 = new ContentMetadataKeyHierarchyLevel();
      hierarchyLevel1.setCustomTargetingKeyId(customTargetingKeyId1);
      hierarchyLevel1.setHierarchyLevel(1);
      hierarchyLevels.add(hierarchyLevel1);
      
      ContentMetadataKeyHierarchyLevel hierarchyLevel2 = new ContentMetadataKeyHierarchyLevel();
      hierarchyLevel2.setCustomTargetingKeyId(customTargetingKeyId2);
      hierarchyLevel2.setHierarchyLevel(2);
      hierarchyLevels.add(hierarchyLevel2);
      
      ContentMetadataKeyHierarchy contentMetadataKeyHierarchy = new ContentMetadataKeyHierarchy();
      contentMetadataKeyHierarchy.setName("Content hierarchy #" + new Random()
          .nextInt(Integer.MAX_VALUE));
      contentMetadataKeyHierarchy.setHierarchyLevels(
          hierarchyLevels.toArray(new ContentMetadataKeyHierarchyLevel[] {}));
      
      // Create the content metadata key hierarchy on the server.
      ContentMetadataKeyHierarchy[] contentMetadataKeyHierarchies = contentMetadataKeyHierarchyService
          .createContentMetadataKeyHierarchies(new ContentMetadataKeyHierarchy[] {
              contentMetadataKeyHierarchy});
      
      for (ContentMetadataKeyHierarchy createdContentMetadataKeyHierarchy : 
          contentMetadataKeyHierarchies) {
        System.out.printf("A content metadata key hierarchy with ID %d, name '%s', and %d "
            + "levels was created.%n", createdContentMetadataKeyHierarchy.getId(), 
            createdContentMetadataKeyHierarchy.getName(),
            createdContentMetadataKeyHierarchy.getHierarchyLevels().length);
      }
  
    }
docs: Runs the example.
  
  @param adManagerServices the services factory.
  @param session the session.
  @param customTargetingKeyId1 the ID of the custom targeting key for the first level.
  @param customTargetingKeyId2 the ID of the custom targeting key for the second level.
  @throws ApiException if the API request failed with one or more service errors.
  @throws RemoteException if the API request failed due to other errors.