A locker including a compartment system having several movable compartments and a casing placed around the system. The casing is provided with at least one opening (40), in front of which the movable compartments are placeable for insertion of luggage to be stored or for taking back stored luggage. The locker is provided with a processing unit (19) provided with a memory (27). In the memory the processing unit stores a code for each compartment including information of whether the compartment is occupied or not. The processing unit controls a driving mechanism (11) for the system. When one of the compartments has become occupied, the processing unit (19) changes the information in the memory from unoccupied to occupied mode, searches through the memory after a compartment having an unoccupied mode, which fulfils predetermined preference demands and which has the shortest pathway to said opening or openings, and controls the driving mechanism (11) to place this compartment in front of the opening or one of the openings.