PIM-2554: Add method to build query